一分心灵的宁静

在滚滚红尘,繁杂人世里,能够保持一分心灵的宁静,随时回到自己的内心深处,细细品味生命的奥妙,无疑是一种修身养性的人生境界

导航

查出特殊符号并取值

Posted on 2006-05-15 12:50  有缘无份  阅读(210)  评论(1)    收藏  举报
查找是否有逗号并取值
 1private 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}