本文實例講述了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 USAGEclass 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#程序設計有所幫助。
新聞熱點
疑難解答