您的位置:首页 > 其它

字符串截取的问题

2006-11-26 13:47 260 查看
用C#写的处理代码,有待改进:

string s = "张三(10),李四(20),王五(30),赵六(40)";
int[] num=new int[20]; //该数组用来存储id号
int i=0,count=0; //count用于统计有多少个id
int index1, index2 = 0;
while (true)
{
index1 = s.IndexOf('(');
index2 = s.IndexOf(')');
num[i] = int.Parse(s.Substring(index1 + 1, index2 - index1 - 1));
count++;
if (index2 + 1 == s.Length)
break;
else
{
s = s.Substring(index2 + 2);
i++;
}
}
for(int j=0;j<i+1;j++)
{
Console.WriteLine(num[j]);
}
Console.WriteLine(count);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: