I have a string that has some Environment.Newline in it. I'd like to strip those from the string and instead, replace the Newline with something like a comma.
What would be, in your opinion, the best way to do this using C#.NET 2.0?
trim() . The trim method removes any leading or trailing whitespace from a string, including spaces, tabs and all line breaks.
To trim a string like that we use C#'s Trim() method. One version of this method accepts characters to cut from both sides of the string. When we specify the carriage return character ( \r ) and line feed character ( \n ) there, the method removes all leading and trailing newlines.
Use String. trim() method to get rid of whitespaces (spaces, new lines etc.) from the beginning and end of the string.
The rstrip() method removes any trailing character at the end of the string. By using this method, we can remove newlines in the provided string value.
Why not:
string s = "foobar\ngork";
string v = s.Replace(Environment.NewLine,",");
System.Console.WriteLine(v);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With