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); }
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;个人觉得二楼大哥的方便好。
string[] strs = { "s11205y", "z82194b", "s11217", "12306" };
strs.Where(a=>Char.IsDigit(a[a.Length - 1])).ToList().ForEach(a => Console.WriteLine(a))
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
=============================== 我要的结果为
s11205y 5
z82194b 4
s11217 7
12306. 6谢谢各位,
{
string ma = Regex.Match(myGridView1.Rows[i].Cells[0].Value.ToString(), "\\d",RegexOptions.RightToLeft).Value; MessageBox.Show(ma);
}
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;个人觉得二楼大哥的方便好。