日期:2014-05-17  浏览次数:20859 次

winform 简单字符串截取问题(求解)
字符串:P235/50R18

如何把这个字符串赋值给以下三个文本框?

最终结果如下:

textbox1="235"
textbox2="50"
textbox3="18"

字符串是变量,也可能是“P235/50 ZR18”

请问如何截取这组字符串的三个数字部分?

求路人解答。万分谢谢!!!


------解决方案--------------------
foreach(Match m in Regex.Matches("P235/50 ZR18","\\d+"))
{
m.Value就是你想要的
}
------解决方案--------------------
foreach(Match m in Regex.Matches("P235/50 ZR18","\\d+"))
{
//m.Groups[0]
//235
50
18
}

------解决方案--------------------
using System.Text.Regularexpression;
------解决方案--------------------
添加命名空间using System.Text.Regularexpression;

foreach(Match m in Regex.Matches("P235/50 ZR18","\\d+"))
{
textbox1=m.Groups[0].Value;
textbox2=m.Groups[1].Value;
textbox3=m.Groups[2].Value;
Response.Write(textbox1+textbox2+textbox3);
}