How to replace the following character with an empty space?
One of my datatable column value looks like the below,
alt text http://img101.imageshack.us/img101/200/datatable.jpg
How to replace that character which is square in shape with a \n
or an empty space us开发者_运维技巧ing c#?
Any suggestion...
ClientAddress
column holds value of a Multiline textbox....
The above character gets inserted into my table from a multiline textbox when the user enters a word and hits enter key and then types another word...
I would do a simple substitution, but since you don't know exactly what character it is you need to address it differently. Using LINQ and string.Join you could replace any control character with a newline or space and assign the result to a new string.
var printableClientAddress =
string.Join( "", client.ClientAddress
.Select( c => char.IsControl(c)
? Environment.NewLine
: c )
.ToArray() );
It is almost certainly the case that the square shape is really just used to indicate a character that's not in the font used to display the string. In other words, it could be any of thousands of characters, the set of which differs for different fonts. It's hard to tell you what to do without knowing your situation.
If your situation is that the square always represents the Enter key and you're displaying the results in HTML, you would need something like ClientAddress.Replace("\n", "<br>")
.
You coucld use the Replace function:
UPDATE tablename
SET ClientAddress = Replace(ClientAddress, '□', '\n');
Where you need to change □
to what's really inside the database.
That square is probably a char which isn't supported by your charset. You'll need to check whether each char's numeric value is inside the printable range of your charset, and if not, replace it.
精彩评论