当前位置: 代码迷 >> ASP.NET >> 怎样提取TextBox里面的数字?解决方案
  详细解决方案

怎样提取TextBox里面的数字?解决方案

热度:9294   发布时间:2013-02-25 00:00:00.0
怎样提取TextBox里面的数字?
如题:怎样提取TextBox里面的数字?
别的控件需要“引用提取出来的值”,如何实现?
请教高手!

------解决方案--------------------------------------------------------
using System.Text.RegularExpressions;

.........

string str1 = TextBox.Text; //源字符串,如:“我是83年的”
string str2 = @"\d+"; //正则表达式,匹配数字串的

MatchCollection Matches = Regex.Matches(str1, str2);

foreach (Match NextMatch in Matches)
{
string num = NextMatch.Value;
//可以取出字符串中的数字,如果字符串中有多个如"aa11bb23"那么可以循环取出"11"和"22"
}
  相关解决方案