我有话想A 1
,A 12
,A 123
,为B 1
A 1234
相同,B 12
,B 123
,B 1234
其中123我这样做的时候意味着三位 现在:获取完整的单词
MatchCollection ForA1 = Regex.Matches(inFile, @"\b(A [0-9])\b");
MatchCollection ForA2 = Regex.Matches(inFile, @"\b(A [0-9][0-9])\b");
.... and so on for three and four digits and B; total 8 lines
减少代码我做到了这一点:
MatchCollection ForAB1 = Regex.Matches(inFile, @"\b(A [0-9]|B [0-9])\b");
MatchCollection ForAB2 = Regex.Matches(inFile, @"\b(A [0-9][0-9]|B [0-9][0-9])\b");
.... and so on for three and four digits; total 4 lines
现在,我想这样做:
MatchCollection ForAB1234 = Regex.Matches(inFile, @"\b(A [0-9]|B [0-9]...
|A [0-9][0-9]|B [0-9][0-9] and so on for three and four digits)\b"); total 1 line
此时比赛后我这样做:
foreach (Match m in ForAB1)
{
//many calculations on the basis of index and length etc
}
我想要什么:
foreach (Match m in ForAB1)
{
if(Match is 'A [0-9]')
{//many calculations on the basis of index and length etc}
else...
}
还有什么事很简单,让我不必简单地重复代码由于不同的数字位数?我正在寻找我管道的所有不同的比赛。
编辑:真正的问题是,我不希望m.len,然后检查它是否是A或B因为在现实中我有超过30个这样的表情
没有违法,但如果你有-1这个问题应该有,适当的理由,我想你可以在这里写 –