修剪不删除多个空格

时间:2016-01-31 14:24:48

标签: c# string replace trim removing-whitespace

我有以下非常简单的例子;

 string MyString = "Egyptian Soccer/Egyptian Premier/Fixtures 20 January  /El Shorta v El Geish";

 string[] description = MyString.Split('/');

 description.Select(s => s.Trim());

然而,' Fixtures 20 January'的字符串值没有删除最后的空格。

我做错了什么?

1 个答案:

答案 0 :(得分:2)

您需要重新分配选择操作的结果

string MyString = "Egyptian Soccer/Egyptian Premier/Fixtures 20 January  /El Shorta v El Geish";

string[] description = MyString.Split('/');
var result = description.Select(s => s.Trim());
foreach(string s in result)
    Console.WriteLine("|" + s + "|");