Replace Line Breaks in a String C#

YonahW picture YonahW · Oct 26, 2008 · Viewed 595.1k times · Source

How can I replace Line Breaks within a string in C#?

Answer

Corin Blaikie picture Corin Blaikie · Oct 26, 2008

Use replace with Environment.NewLine

myString = myString.Replace(System.Environment.NewLine, "replacement text"); //add a line terminating ;

As mentioned in other posts, if the string comes from another environment (OS) then you'd need to replace that particular environments implementation of new line control characters.