C#正則檢拆字符串能否字母數字混編的辦法。本站提示廣大學習愛好者:(C#正則檢拆字符串能否字母數字混編的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#正則檢拆字符串能否字母數字混編的辦法正文
本文實例講述了C#正則檢拆字符串能否字母數字混編的辦法。分享給年夜家供年夜家參考。詳細以下:
using System.Text;
using System.Text.RegularExpressions;
public static class StringExtensions
{
public static bool IsAlphanumeric(this string source)
{
Regex pattern = new Regex("[^0-9a-zA-Z]");
return !pattern.IsMatch(source);
}
}
// EXAMPLE USAGE
class Program
{
static void Main(string[] args)
{
string testString = Console.ReadLine();
if (testString.IsAlphanumeric())
Console.WriteLine("Yep!");
else
Console.WriteLine("Nope!");
Console.ReadKey(); // Wait for key before exiting
}
}
願望本文所述對年夜家的C#法式設計有所贊助。