chenping-987123

从字符串中提取数字,有两种方法:

(1)code:

String str ="abc.htm?id=16034$a=343";

 

            String count=null;
foreach (char c in str)
{
if (c >= \'0\' && c <= \'9\')
{
count
+= c.ToString();
}
else
{
if (count != null)
{
Response.Write(count
+"<br/>");
count
= null;
}
}
}
if (count != null)
{
Response.Write(count);
count
= null;
}
(2) regex:
String str = "abc.htm?id=16034$a=343";
Regex regex
= new Regex(@"\d+");
MatchCollection cc
= regex.Matches(str, 0);
foreach (Match match in cc)
{
Response.Write(match.Value
+"<br/>");
}

 

 

分类:

技术点:

相关文章:

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