Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove specific character from a string based on hex value

Tags:

string

c#

hex

While importing data from a flat file, I noticed that some of lines have embedded non breaking spaces (Hex: A0).

I would like to remove these, but the standard string.replace doesn't seem to work and had considered using regex to replace the string but wouldn't know what the regex would search for to remove it.

Rather than converting the whole string to hex and examining that, is there a better way?

like image 588
Andy Evans Avatar asked Dec 15 '10 21:12

Andy Evans


2 Answers

Regex.Replace(input, "\xA0", String.Empty);

This ought to do it.

like image 180
KeithS Avatar answered Sep 19 '22 15:09

KeithS


Why doesn't string.Replace work?

stringVar.Replace((char)0xA0, ' ');
like image 42
Jackson Pope Avatar answered Sep 21 '22 15:09

Jackson Pope