ex-10-07
来自「Programming Csharp Source Code(代码) Prog」· 代码 · 共 38 行
TXT
38 行
// Example 10-07: Using MatchCollection and Match
namespace Programming_CSharp
{
using System;
using System.Text.RegularExpressions;
class Test
{
public static void Main()
{
string string1 = "This is a test string";
// find any nonwhitespace followed by whitespace
Regex theReg = new Regex(@"(\S+)\s");
// get the collection of matches
MatchCollection theMatches =
theReg.Matches(string1);
// iterate through the collection
foreach (Match theMatch in theMatches)
{
Console.WriteLine(
"theMatch.Length: {0}", theMatch.Length);
if (theMatch.Length != 0)
{
Console.WriteLine("theMatch: {0}",
theMatch.ToString());
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?