c# remove line breaks from string code example
Example 1: c# remove newline from string
// Remove all newlines from the 'example' string variable
string cleaned = example.Replace("\n", "").Replace("\r", "");
Example 2: remove carriage returns from string c#
// Remove newlines from both sides of the 'example' string variable
string cleaned = example.Trim('\r', '\n');