【发布时间】:2013-06-01 23:55:09
【问题描述】:
我知道System.String.Split(null) 应该返回给我一个删除了空格的字符串数组。我读过this post 和this MSDN doc,这与我的经历不符。
这是我的代码:
void MyFunction(string info)
{
print(info);
print(Char.IsWhiteSpace(info,0));
print(Char.IsWhiteSpace(info,1));
print(Char.IsWhiteSpace(info,2));
print(Char.IsWhiteSpace(info,3));
print(Char.IsWhiteSpace(info,4));
print(Char.IsWhiteSpace(info,5));
print(Char.IsWhiteSpace(info,6));
print(Char.IsWhiteSpace(info,7));
print(Char.IsWhiteSpace(info,8));
print(Char.IsWhiteSpace(info,9));
print(Char.IsWhiteSpace(info,10));
print(Char.IsWhiteSpace(info,11));
string [] split = info.Split();
foreach(string s in split)
print(s);
}
这是输出:
628 5911.3097 1660.0134 3771.8285 0 错误的 错误的 错误的 真的 真的 真的 真的 真的 真的 错误的 错误的 错误的 628 (空的) (空的) (空的) (空的) (空的) 5911.3097 (空的) (空的) (空的) (空的) (空的) 1660.0134 (空的) (空的) (空的) (空的) (空的) 3771.8285在我看来,System.String.Split(null) 刚刚为我删除了一个空格:S
我正在使用:Unity3D、Mono、C#、Mac OSX 10.8
【问题讨论】:
-
Split 返回一个字符串数组,其中包含此实例中由元素分隔的子字符串。所以这里它返回子字符串...找到的每个空格...它不会删除空格...
-
如果两个分隔符相邻,或者在该实例的开头或结尾找到一个分隔符,则对应的数组元素包含Empty.so它不是空格它为空......
-
@AmitSingh 谢谢!我已经在我的问题中编辑了输出。