我如何根据字符串的数量匹配某些内容?

时间:2015-12-11 15:37:38

标签: c# .net

如何匹配17位数字出现在字符串中然后使用它们的次数?语言是c#/。net

1 个答案:

答案 0 :(得分:0)

你可以用一个简单的正则表达式做到这一点,但你应该在尝试使用它们之前阅读一些MSDN文章"

 // Match a Regex and Do Stuff
        public void showMatch(string input, string expr)
        {
            MatchCollection mc = Regex.Matches(input, expr); 
            int num = 0;  
            foreach (Match m in mc)
            {
                string tm = m.ToString();
                num++;
                if (num == 1)
                {
                    // Do Stuff if 1 match.
                }
                if (num == 2)
                {
                    // Do Stuff if 2 matches.
                }
            }
       }


            // showMatch(input, @"(?:[0-9]+){17}");

MSDN Article