使用正则表达式:
str = Regex.Replace(str, @"\D+", "");
Run Code Online (Sandbox Code Playgroud)
\D是\d- 补充所有不是数字的东西.+将匹配其中一个或多个(它通常比一个一个好一点).
使用Linq(在.Net 4.0上):
str = String.Concat(str.Where(Char.IsDigit));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
490 次 |
| 最近记录: |