怎么提取这样的字符串12*36=2 怎么提取这样的字符串12*36=2 分别提取 12 和 36 还有 2出来 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string a="12*36=2";string[] b=a.Split('*');string[] c=b.Split('='); string a="12*36=2"; string[] b=a.Split('*'); string[] c=b.Split('=');上面这种方式可以实现也可以用正则来实现 string exp = "12 * 36 = 2";Regex reg = new Regex(@"\d+");MatchCollection matches = reg.Matches(exp);// matches[0].Value 为 12// matches[1].Value 为 36// matches[2].Value 为 2用正则好一点,加减乘除都可以,数字前后有几个空格也没关系,包含多个超过三个数字的运算式也可以依次获取到其余的数字。 12*36=2 ??哪来的?string exp = "12 * 36 = 2";Regex reg = new Regex(@"\d+");MatchCollection matches = reg.Matches(exp);// matches[0].Value 为 12// matches[1].Value 为 36// matches[2].Value 为 2 String str = "12 * 36 = 2"; Regex objRegex = new Regex(@"\s*(?<First>\d+)\s*\*\s*(?<Second>\d+)\s*=\s*(?<Third>\d+)\s*"); MatchCollection objCollection = objRegex.Matches(str); for (int i = 0; i < objCollection.Count; i++) { Response.Write( "第一个:" + objCollection[i].Groups["First"].Value + "第二个:" + objCollection[i].Groups["Second"].Value + "第三个:" + objCollection[i].Groups["Third"].Value + "<br/>"); } ////结果为: ////第一个:12第二个:36第三个:2 找个高手帮忙写个html框架页面 ListBox控件,代码不懂 服务器控件checkbox问题 sql查询时间段的问题!! C#好还是JAVA好 我只要两分 关于web.config权限验证的问题? 如果页面出错或者访问的页面不存在,有没有办法可以转到指定的页面? 一个小问题 我想让button服务器控件先执行客户端代码再提交,如果实现? 学习 C/S模式开发转ASP.NET怎么样啊?
string[] b=a.Split('*');
string[] c=b.Split('=');
string[] b=a.Split('*');
string[] c=b.Split('=');上面这种方式可以实现也可以用正则来实现
Regex reg = new Regex(@"\d+");
MatchCollection matches = reg.Matches(exp);
// matches[0].Value 为 12
// matches[1].Value 为 36
// matches[2].Value 为 2
用正则好一点,加减乘除都可以,数字前后有几个空格也没关系,包含多个超过三个数字的运算式也可以依次获取到其余的数字。
string exp = "12 * 36 = 2";
Regex reg = new Regex(@"\d+");
MatchCollection matches = reg.Matches(exp);
// matches[0].Value 为 12
// matches[1].Value 为 36
// matches[2].Value 为 2
Regex objRegex = new Regex(@"\s*(?<First>\d+)\s*\*\s*(?<Second>\d+)\s*=\s*(?<Third>\d+)\s*"); MatchCollection objCollection = objRegex.Matches(str);
for (int i = 0; i < objCollection.Count; i++)
{
Response.Write(
"第一个:" + objCollection[i].Groups["First"].Value +
"第二个:" + objCollection[i].Groups["Second"].Value +
"第三个:" + objCollection[i].Groups["Third"].Value + "<br/>");
} ////结果为:
////第一个:12第二个:36第三个:2