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

19 s
19

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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *