I have a need to get rid of all line breaks that appear in my strings (coming from db). I do it using code below:
value.Replace(\"\\r\\n\", \"\").Replace(\"\\n\"
If you've a string say "theString" then use the method Replace and give it the arguments shown below:
theString = theString.Replace(System.Environment.NewLine, "");
Props to Yossarian on this one, I think he's right. Replace all whitespace with a single space:
data = Regex.Replace(data, @"\s+", " ");
According to wikipedia, there are numerous line terminators you may need to handle (including this one you mention).
LF: Line Feed, U+000A
VT: Vertical Tab, U+000B
FF: Form Feed, U+000C
CR: Carriage Return, U+000D
CR+LF: CR (U+000D) followed by LF (U+000A)
NEL: Next Line, U+0085
LS: Line Separator, U+2028
PS: Paragraph Separator, U+2029
This is my first attempt at this, but I think this will do what you want....
var controlChars = from c in value.ToCharArray() where Char.IsControl(c) select c;
foreach (char c in controlChars)
value = value.Replace(c.ToString(), "");
Also, see this link for details on other methods you can use: Char Methods
I'd recommend removing ALL the whitespace (char.IsWhitespace), and replacing it with single space.. IsWhiteSpace takes care of all weird unicode whitespaces.
Assuming that 8232 is unicode, you can do this:
value.Replace("\u2028", string.Empty);