查找是否有逗号并取值
1
private string StrCheckBox(string checkbox)
2
{
3
string result = string.Empty;
4
int cnt = 0;
5
int idx = 0;//是否找到,
6
for (int i = 0; i < checkbox.Length; )
7
{
8
idx = checkbox.IndexOf(",", i);
9
if (idx >= 0)
10
{
11
cnt++;
12
i = idx + 1;
13
}
14
else
15
{
16
break;
17
}
18
}
19
string[] str = new string[cnt + 1];
20![]()
21![]()
22
for (int i = 0, j = 0; i < checkbox.Length && j < cnt + 1; j++)
23
{
24
idx = checkbox.IndexOf(",", i);
25
if (idx >= 0)
26
{
27
str[j] = checkbox.Substring(i, idx - i);
28
i = idx + 1;
29
}
30
else
31
{
32
str[j] = checkbox.Substring(i, checkbox.Length - i);
33
}
34
}
35
}
private string StrCheckBox(string checkbox)2
{3
string result = string.Empty;4
int cnt = 0;5
int idx = 0;//是否找到,6
for (int i = 0; i < checkbox.Length; )7
{8
idx = checkbox.IndexOf(",", i);9
if (idx >= 0)10
{11
cnt++;12
i = idx + 1;13
}14
else15
{16
break;17
}18
}19
string[] str = new string[cnt + 1];20

21

22
for (int i = 0, j = 0; i < checkbox.Length && j < cnt + 1; j++)23
{24
idx = checkbox.IndexOf(",", i);25
if (idx >= 0)26
{27
str[j] = checkbox.Substring(i, idx - i);28
i = idx + 1;29
}30
else31
{32
str[j] = checkbox.Substring(i, checkbox.Length - i);33
}34
}35
}

浙公网安备 33010602011771号