How to remove empty lines from a formatted string?

后端 未结 11 1579
一生所求
一生所求 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:41

    This pattern works perfect to remove empty lines and lines with only spaces and/or tabs.

    s = Regex.Replace(s, "^\s*(\r\n|\Z)", "", RegexOptions.Multiline)
    

提交回复
热议问题