【发布时间】:2017-12-30 08:30:25
【问题描述】:
这是示例代码。
我可以连接所有字符串并用空格分隔它们。
如果字符串是Empty,连接将被忽略,防止出现双空格。
如何在相同的ColorList.Where() 参数中也忽略换行符\n?
string red = "Red";
string blue = "Blue";
string yellow = "\n\n";
string green = string.Empty;
List<string> ColorList = new List<string>()
{
red,
blue,
yellow,
green
};
string colors = string.Join(" ", ColorList.Where(s => !string.IsNullOrEmpty(s)));
【问题讨论】:
标签: c# string removing-whitespace