C#中的split函数得到字符换数组后如何得到该字符串数组的数组个数?

如题所述

用,分割
string s = "a,b,c,d,e";
string [] strs = s.Split(",");
int i = strs.Length;
Console.WriteLine(i);
拿去执行

小扩展一下 比如说你两个字母中间多打了一个逗号那拆出来的话 数组strs中就会多一个元素,长度会加1 可以这样避免

string s = "a,b,c,d,e";
string [] strs = s.Split(new string[]{","},StringSplitOptions.RemoveEmptyEntries);
int i = strs.Length;
Console.WriteLine(i);

直接执行吧
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-04-17
string strs[]=s.split(',');
长度 strs.Length
相似回答