有一个字符串,如12,1221,3231,1233,123,
如何把字符串中的数字一个个选择出来
如12   1221   3231   1233  123

解决方案 »

  1.   

    "12,1221,3231,1233,123".Split(',')
      

  2.   


    string s = "12,1221,3231,1233,123,";
                foreach (Match m in Regex.Matches(s, @"\d+"))
                {
                    Console.WriteLine(m.Value);
                }
                Console.Read();
      

  3.   

    string str = "12,1221,3231,1233,123,";
                    str=str.Replace(',',' ');
      

  4.   

                string a="12,1221,3231,1233,123";
                string[] num = a.Split(',');
                foreach (string _num in num)
                {            }
      

  5.   

    string s = "12,1221,3231,1233,123,";
    string [] ss=s.split(",");
      

  6.   

    split函数得到的就是字符串数组
      

  7.   

    split,得到字符串数组,然后再循环遍历输出
      

  8.   

    split函数可以得到一个字符串数组,但是如果你原始没分解的字符串中有字母的话,split也会把字母分割出来。用正则表达式的话,可以设置想要的任何格式,也不一定是有特殊的分隔符才可以的。
      

  9.   

    "12,1221,3231,1233,123".Split(',')=>var result = from s in  "12,1221,3231,1233,123".Split(',')
                       select new { int.Parse(s)}
      

  10.   

    s="12,1221,3231,1233,123,";
    string[] ar = s.Split('',StringSplitOptions.RemoveEmptyEntries);
      

  11.   

    用isnumberic(),第一个true的index是起始地址,下一个false是终止地址,两者之间就是数字组合的全部。当中的分隔符可以是任意非数字字符。for (int cycInt = 0; cycInt < str.Length; cycInt++)
                {
                    if (char.IsNumber(str[cycInt]))
                    {
                    }
                    else if (str[cycInt]!= '.')
                    {
                        MessageBox.Show("The input charactor: "+ str[cycInt].ToString()+" is not number!");
                        dgvCalTable.Rows[tempRow].Cells[tempCell].Value = arrayValue[tempRow * y + tempCell];
                        fillRowData();
                        return;
                    }
                }
      

  12.   

    这个时候千万别秀正则,replace已经足够了。
      

  13.   

    用Split()函数,截取字符串数组。然后遍历字符串数组利用int.TryParse()函数转化成数值。
      

  14.   

    这个值是gridview中的一个值
    GridView1.Rows[i].Cells[1].ToString().Split(",");总是会报错,为何如此。
      

  15.   

    (GridView1.Rows[i].Cells[1]??"").ToString().Split(",");
      

  16.   

    与“string.Split(params char[])”最匹配的重载方法具有一些无效参数
      

  17.   

    GridView1.Rows[i].Cells[1].ToString().Split(',');