本文整理匯總了C#中System.Text.RegularExpressions.MatchCollection.Count屬性的典型用法代碼示例。如果您正苦於以下問題:C# MatchCollection.Count屬性的具體用法?C# MatchCollection.Count怎麽用?C# MatchCollection.Count使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Text.RegularExpressions.MatchCollection
的用法示例。
在下文中一共展示了MatchCollection.Count屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\d+";
string[] inputs = { "This sentence contains no numbers.",
"123 What do I see?",
"2468 369 48 5" };
foreach (var input in inputs) {
MatchCollection matches = Regex.Matches(input, pattern);
Console.WriteLine("Input: {0}", input);
if (matches.Count == 0)
Console.WriteLine(" No matches");
else
foreach (Match m in matches)
Console.WriteLine(" {0} at index {1}", m.Value, m.Index);
Console.WriteLine();
}
}
}
輸出:
Input: This sentence contains no numbers. No matches Input: 123 What do I see? 123 at index 0 Input: 2468 369 48 5 2468 at index 0 369 at index 5 48 at index 9 5 at index 12