读书人

求一算法~该怎么处理

发布时间: 2012-12-21 12:03:49 作者: rapoo

求一算法~~~~
已知字符串 “a1b22c3333”
如何取出相对应数字的方法
求简单点的方法
[最优解释]


using System.Text.RegularExpressions;


string str = "a1b22c3333";
foreach (Match match in Regex.Matches(str, @"\d+"))
Console.WriteLine(match.Value);


[其他解释]
string str = "a1b22c3333";
var ary = Regex.Matches(str, @"([a-zA-Z]+)(\d+)").Cast<Match>().Select(t => new { eng = t.Groups[1].Value, shuzi = t.Groups[2].Value }).ToArray();
foreach (var tt in ary)
Console.WriteLine(tt.eng + ":" + tt.shuzi);

[其他解释]
引用:
C# code?123456using System.Text.RegularExpressions; string str = "a1b22c3333"; foreach (Match match in Regex.Matches(str, @"\d+")) Console.WriteLine……
+1
[其他解释]
引用:
C# code?123456using System.Text.RegularExpressions; string str = "a1b22c3333"; foreach (Match match in Regex.Matches(str, @"\d+")) Console.WriteLine……


怎么取前面的英文字母然后对应呢?
[其他解释]
引用:
引用:C# code?123456using System.Text.RegularExpressions; string str = "a1b22c3333"; foreach (Match match in Regex.Matches(str, @"\d+")) ……

就不能一次问完……

string str = "a1b22c3333";
foreach (Match match in Regex.Matches(str, @"([a-zA-Z]+)(\d+)"))
Console.WriteLine("字母:" + match.Groups[1].Value + ",数字:" + match.Groups[2].Value);


[其他解释]


结贴给分

读书人网 >asp.net

热点推荐