更新时间:2023-12-03 19:38:40
如果您要删除包含任何空白(制表符,空格)线,请尝试:
If you want to remove lines containing any whitespace (tabs, spaces), try:
string fix = Regex.Replace(original, @"^\s*$\n", string.Empty, RegexOptions.Multiline);
Edit(对于@Will):修剪后的新行最简单的办法是使用的 TrimEnd
上生成的字符串,例如:
Edit (for @Will): The simplest solution to trim trailing newlines would be to use TrimEnd
on the resulting string, e.g.:
string fix =
Regex.Replace(original, @"^\s*$\n", string.Empty, RegexOptions.Multiline)
.TrimEnd();