c#字符串中截取数字
{"5412855X1X22","5412855X1X2SQ001","5412855X1X212_file","5412855X1X315_maefs","541285...
{ "5412855X1X22", "5412855X1X2SQ001", "5412855X1X212_file", "5412855X1X315_maefs","5412855X1X2SQ001SQ002"........... }
有这么几种类型的的字符串,想要得到第二个X后面的数字,
也就是:22,2,212,315,2
数字位数不定,数字后面可能是字母,也可能是特殊字符,希望可以用正则截取出来 展开
有这么几种类型的的字符串,想要得到第二个X后面的数字,
也就是:22,2,212,315,2
数字位数不定,数字后面可能是字母,也可能是特殊字符,希望可以用正则截取出来 展开
1个回答
展开全部
static void Main(string[] args)
{
string s = "纸箱55*46.5*37.5";
Regex r = new Regex(@"(\d+\.?\d*)");
var matches = r.Matches(s).OfType<Match>().ToArray();
string s1 = matches[0].Groups[0].Value;
string s2 = matches[1].Groups[0].Value;
string s3 = matches[2].Groups[0].Value;
}
{
string s = "纸箱55*46.5*37.5";
Regex r = new Regex(@"(\d+\.?\d*)");
var matches = r.Matches(s).OfType<Match>().ToArray();
string s1 = matches[0].Groups[0].Value;
string s2 = matches[1].Groups[0].Value;
string s3 = matches[2].Groups[0].Value;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询