当我用C#编程时,使用拆分功能:
string[] singleStr=str.Split(';');
str是
column111.dwg&186&0;
为什么
singleStr.Length=2
?为什么通过数组为null给出数组?
最佳答案
我不确定desStr
是什么样子,但听起来您需要使用StringSplitOptions.RemoveEmptyEntries
返回值不包括包含空的数组元素
串
string str = "column111.dwg&186&0;";
string[] singleStr = str.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in singleStr)
{
Console.WriteLine(item);
}
输出将仅为;
column111.dwg&186&0
这里是
demonstration
如果在这种情况下不使用
StringSplitOptions.RemoveEmptyEntries
,则singleStr
数组有2个项目; column111.dwg&186&0
和""
关于c# - 为什么Split函数有两个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20419543/