How to remove new line characters from a string?

I like to use regular expressions. In this case you could do:

string replacement = Regex.Replace(s, @"\t|\n|\r", "");

Regular expressions aren’t as popular in the .NET world as they are in the dynamic languages, but they provide a lot of power to manipulate strings.

Leave a Comment