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

📄 3.10.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 3.10 Using Regular Expressions to Replace Numbers in a Credit Card with xs
using System;
using System.Text.RegularExpressions;
namespace _12_RegExpReplace
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Regex cardExp = new Regex( @”(\d{4})-(\d{4})-(\d{4})-(\d{4})” );
string safeOutputExp = “$1-xxxx-xxxx-$4”;
string cardNum;
Console.Write( “Please enter your credit card number: “ );
cardNum = Console.ReadLine();
while( cardExp.Match( cardNum ).Success == false )
{
Console.WriteLine( “Invalid card number. Try again.” );
Console.Write( “Please enter your credit card number: “ );
cardNum = Console.ReadLine();
}
Console.WriteLine( “Secure Output Result = {0}”,
cardExp.Replace( cardNum, safeOutputExp ));
}
}
}

⌨️ 快捷键说明

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