string hits=@"1,58; 1167; 1,11; 2154; 3,15; 4,11; 4,16; 14;13 ";请问如何把hits
string hits=@"1,58; 1,167; 1,11; 2,154; 3,15; 4,11; 4,16; 14,13 ";
string [] temp = hits.Split(';');
int [] result = new int[temp.Length];
int count = 1;
result[0] = Convert.ToInt32 ( temp[0].Split(',')[0] );
for ( int i = 1; i < temp.Length; i++ ) 
...{
int num = Convert.ToInt32 ( temp[i].Split(',')[0] );
if ( result[count - 1] != num ) 
...{
result[count] = num;
count++;
}
}
String answer = "1:3;2:2";
//将String用;分成一个字符串数组
string [] result= answer.Split(';');
//可以再去每个的制
for (int i = 0; i < result.Length-1; i++)
...{
int b=Convert.ToInt32(result[i-1].Split(':')[1]);
MessageBox.Show("数字{0}",b);
}

本文介绍了一种使用 C# 对复杂字符串进行处理的方法,包括如何从特定格式的字符串中提取数字并转换为整数数组,同时展示了如何进一步解析另一种格式的字符串数组。
1113

被折叠的 条评论
为什么被折叠?



