用,分割
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);
直接执行吧
温馨提示:内容为网友见解,仅供参考