提取字符串中的数字

时间:2025-03-11 22:28:26
一、使用正则表达式
 string str = "sztq数字提取123sztq数字提取";
 string result = (str, @"[^0-9]+", "");
 ("使用正则表达式提取");
 (result);
二、使用ASCII码
string str = "sztq数字提取123sztq数字提取";
 foreach (char c in str)
         {
             if (Convert.ToInt32(c) >= 48 && Convert.ToInt32(c) <= 57)
              {
                  (c);
              }
         }
 ("使用ASCII码提取");
 (());