转自:http://www.cnblogs.com/dolphin-gjh/p/6121792.html

一、使用正则表达式

1 string str = "sztq数字提取123sztq数字提取";
2 string result = System.Text.RegularExpressions.Regex.Replace(str, @"[^0-9]+", "");
3 Console.WriteLine("使用正则表达式提取");
4 Console.WriteLine(result);


二、使用ASCII码

C# 字符串提取数字
 1  string str = "sztq数字提取123sztq数字提取";
 2  foreach (char c in str)
 3          {
 4              if (Convert.ToInt32(c) >= 48 && Convert.ToInt32(c) <= 57)
 5               {
 6                   sb.Append(c);
 7               }
 8          }
 9  Console.WriteLine("使用ASCII码提取");
10  Console.WriteLine(sb.ToString());

相关文章:

  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
猜你喜欢
  • 2021-07-04
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-03-11
  • 2022-12-23
相关资源
相似解决方案