⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3.11.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 3.11 Enumerating Through the Match Collection to Perform Special
Operations on Each Match in a Regular Expression
static void TestManualGrouping()
{
Regex cardExp = new Regex( @”\d{4}” );
string cardNum;
string safeOutputExp = “”;
Console.Write( “Please enter your credit card number: “ );
cardNum = Console.ReadLine();
if( cardExp.Matches( cardNum ).Count < 4 )
{
Console.WriteLine( “Invalid card number” );
return;
}
foreach( Match field in cardExp.Matches( cardNum ))
{
if( field.Success == false )
{
Console.WriteLine( “Invalid card number” );
return;
}
if( field.Index == 5 || field.Index == 10 )
{
safeOutputExp += “-xxxx-”;
}
else
{
safeOutputExp += field.Value;
}
}
Console.WriteLine( “Secure Output Result = {0}”, safeOutputExp );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -