日期:2014-05-20 浏览次数:21008 次
var sb=new StringBuilder(); foreach(char c in s) { if(c>='0'&&c<='9') { sb.Append(c); } } return sb.ToString()
------解决方案--------------------
正则表达式!
------解决方案--------------------
string s = "d$a#31#d$fc$r%22%f$e$r$43@e$65%g$g&d$z";
string pattern = @"\d+";
MatchCollection matches = Regex.Matches(s, pattern,RegexOptions.Multiline); // Split on hyphens
foreach (Match match in matches)
{
Console.WriteLine("'{0}'", match);
Console.ReadLine();
}
这样的结果是:31 22 43 65
如果string pattern = @"\d";
则结果是3 1 2 2 4 3 6 5
具体知识上面有提的,正则表达式