@gnomixa - What do you mean in your comment that nothing was achieved? In VS2005, the following works for me.
If your goal is to remove newlines, thereby truncating the line, look at this:
string originalStringWithNewline = "12\n345"; // length is 6 System.Diagnostics.Debug.Assert(originalStringWithNewline.Length == 6); string newStringWithoutNewline = originalStringWithNewline.Replace("\n", ""); // new length is 5 System.Diagnostics.Debug.Assert(newStringWithoutNewline.Length == 5);
If your goal is to replace the newline characters with a space character, leaving the string length the same, look at this example:
string originalStringWithNewline = "12\n345"; // length is 6 System.Diagnostics.Debug.Assert(originalStringWithNewline.Length == 6); string newStringWithoutNewline = originalStringWithNewline.Replace("\n", " "); // new length is still 6 System.Diagnostics.Debug.Assert(newStringWithoutNewline.Length == 6);
And you have to replace single-character strings instead of characters, because `` is not a valid character, which should be replaced with Replace (string, char)
JeffH Mar 16 '09 at 19:55 2009-03-16 19:55
source share