string hits=@"1,58; 1167; 1,11; 2154; 3,15; 4,11; 4,16; 14;13 ";请问如何把hits如1,58 1167 的头个数字取出来,得到一个数组里面是1 2 3 4 14.
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);
}