var text = "8798dsfgsd98gs87£%"%001912.43.36.";
var numText = new string( text.Where(c=>char.IsDigit(c)).ToArray() );
Run Code Online (Sandbox Code Playgroud)
编辑:
如果您的目标是性能,请使用StringBuilder:
var text = "8798dsfgsd98gs87£%"%001912.43.36.";
var numText = new StringBuilder();
for(int i = 0; i < text.Length; i++) {
char c = text[i];
if ( char.IsDigit(c) ) {
numText.Append(c);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
180 次 |
| 最近记录: |