tags:

views:

213

answers:

4

One of my datatable column value looks like the below,

alt text

How to replace that character which is square in shape with a \n or an empty space using 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...

A: 

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.

Darin Dimitrov
@Darin look at my edit
Pandiya Chendur
+1  A: 

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>").

Gabe
@gabe it gets inserted into my table from a multiline textbox when the user enters a word and hits enter key and then types another word...
Pandiya Chendur
Since it comes from an enter key, it is almost certainly a newline. If you're trying to display the text in HTML, however, you need to do something like `ClientAddress.Replace("\n", "<br>")`.
Gabe
+2  A: 

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() );
tvanfosson
This doesn't cover unicode characters which aren't supported by the db charset.
k_b
A: 

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.

k_b