解决方案 »

  1.   


                string[] a = { "42MSE0180X0544.5X020M", "42MSE0180X0550X060M", "42MSE0196X0300X025L", "42MSE0194X0400X015", "42MSE0200X0350X115" };
                int[] b = { 0, 0, 0, 0, 0 };
                for (int i = 0; i < a.Length; i++)
                {
                    int xpos = a[i].LastIndexOf("X");//最后一个X位置
                    string r = a[i].Substring(xpos + 1);//后半部分
                    r = System.Text.RegularExpressions.Regex.Replace(r, @"[^\d]+", "");
                    b[i] = int.Parse(r);
                }
      

  2.   

    b[i] = int.Parse(r); 
    改成
    int.TryParse(r, out b[i]);
      

  3.   

    如果这个位置可能出现小数点,还要改一下
    r = System.Text.RegularExpressions.Regex.Replace(r, @"[^\d]+", ""); 
    改成
    r = System.Text.RegularExpressions.Regex.Replace(r, @"[\.^\d]+", ""); 
      

  4.   

    (?<=M)这是什么意思?\d+这个我知道,取数字
      

  5.   

    r = System.Text.RegularExpressions.Regex.Replace(r, @"[\.^\d]+", "");  这个应该是这样 r = System.Text.RegularExpressions.Regex.Replace(r, @"[^\d\.]+", "");  
      

  6.   

       static ArrayList get()
            {
                ArrayList list = new ArrayList();            string[] strList = { "42MSE0180X0544.5X020M", "42MSE0180X0550X060M", "42MSE0196X0300X025L", "42MSE0194X0400X015", "42MSE0200X0350X115" };
                if (null != strList && strList.Length > 0)
                {
                    for (int i = 0; i < strList.Length; i++)
                    {
                        int inStr = strList[i].LastIndexOf("X");
                        string str = strList[i].Substring(inStr + 1, 3);
                        if (!string.IsNullOrEmpty(str))
                        {
                            list.Add(str);
                        }
                    }
                }            return list;
            }