How to remove empty lines from a formatted string?

后端 未结 11 1547
一生所求
一生所求 2020-12-01 02:24

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

11条回答
  •  眼角桃花
    2020-12-01 02:46

    @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

提交回复
热议问题