一些字符串
s11205y
z82194b
s11217
12306.......
我想返回最后一位是数字的字符串

解决方案 »

  1.   


    string[] strs = { "s11205y", "z82194b", "s11217", "12306" };
    strs.Where(a=>Char.IsDigit(a[a.Length - 1])).ToList().ForEach(a => Console.WriteLine(a))
      

  2.   

     string pattern = "[^\\s]*\\d+$";
                for (int i = 0; i < this.myGridView1.Rows.Count; i++)
                {
                    string ma = Regex.Match(myGridView1.Rows[i].Cells[0].Value.ToString(), pattern).Value;                MessageBox.Show(ma);
                }
    只是返回了每串的所有数字!如z82193b   -> 82193 ,我只想要 3
      

  3.   

    不好意思,我描述的不够清楚
    ===============================           我要的结果为
    s11205y    5
    z82194b    4
    s11217     7
    12306.     6谢谢各位,
      

  4.   

        for (int i = 0; i < this.myGridView1.Rows.Count; i++)
                {
                    string ma = Regex.Match(myGridView1.Rows[i].Cells[0].Value.ToString(), "\\d",RegexOptions.RightToLeft).Value;                MessageBox.Show(ma);
                }
      

  5.   

    string[] strs = { "s11205y", "z82194b", "s11217", "12306" };
    Regex myRegex = new Regex("[0-9]$");
    foreach (string s in strs)
    {
    if (myRegex.Match(s).Success == true)
    {
         Console.WriteLine(s);
    }
    }
    Console.ReadLine();注:using System.Text.RegularExpressions;个人觉得二楼大哥的方便好。