Reputation: 7176
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?
Upvotes: 11
Views: 40771
Reputation: 5984
string.Replace does work. Without using RegEx:
stringVar = stringVar.Replace("\xA0", string.Empty);
Upvotes: 7
Reputation: 40736
Would this work for you?
var myNewString = myCurrentString.Replace("\n", string.Empty );
myNewString = myNewString.Replace("\r", string.Empty );
"\n
" is ASCII LineFeed, "\r
" is Return.
Upvotes: 3
Reputation: 14640
Why doesn't string.Replace work?
stringVar.Replace((char)0xA0, ' ');
Upvotes: 26