字符串截取的问题
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);
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);
相关文章推荐
- 用CSS解决中英文混合字符串的截取省略问题的解决办法
- 截取字符串 -- html标签闭合问题
- [转]smarty截取字符串,截取汉字字符串问题解决方法
- 关于字符串截取的一个小问题
- 解析使用substr截取UTF-8中文字符串出现乱码的问题
- 大家来发现截取字符串的问题
- PHP 截取中文字符串乱码问题
- 用CSS解决中英文混合字符串的截取省略问题的解决办法
- 用CSS解决中英文混合字符串的截取省略问题的解决办法
- PHP字符串截取函数(解决中文乱码问题!支持UTF-8和GB2312)
- 截取字符串时的全半角问题
- 解决页面截取中英文字符串长度显示不一致问题
- 字符串的截取问题
- PHP截取中文字符串的问题
- 数据绑定控件,字符串截取问题?
- 字符串截取问题
- 截取一个中英文混合的字符串,不能出现截取半个汉字的问题
- 解决PHP截取中文字符串问题
- 中英混合字符串按字节截取的小问题
- PHP中使用substr()截取字符串出现中文乱码问题该怎么办