How to remove empty lines in a string in C#? I am generating some text files in C# (winforms) and for some reason there are some empty lines. How can I remove them after the
@Tim Pietzcker - Not working for me. I have to change a little bit but thx!
Ehhh C# Regex.. I had to change it again but this working good:
private string RemoveEmptyLines(string lines)
{
return Regex.Replace(lines, @"^\s*$\n|\r", string.Empty, RegexOptions.Multiline).TrimEnd();
}
Example: http://regex101.com/r/vE5mP1/2