How to remove empty lines from a formatted string?

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

    I found simple answer to this problem

    YourradTextBox.Lines = YourradTextBox.Lines.Where(p => p.Length > 0).ToArray();

    Adapted from Marco Minerva [MCPD] at: https://social.msdn.microsoft.com/Forums/windows/en-US/b1bb4107-4ad5-4cd3-bd20-9c2b3f9b31a6/delete-lines-from-multiline-textbox-if-its-contain-certain-string-c?forum=winforms&prof=required

提交回复
热议问题