正则表达式判断字符串是否回文数?

解决方案 »

  1.   

    using System;class Program
    {
      static void Main()
      {
        foreach (string s in new string[] { "123", "121", "2231322" })
        {
          Console.WriteLine("{0}: {1}", s, s == Reverse(s) ? "是回文" : "不是回文");
        }
      }
      
      static string Reverse(string s)
      {
        char[] charArray = s.ToCharArray();
        Array.Reverse(charArray);
        return new string(charArray);
      }
    }
    /* 程序输出:
    123: 不是回文
    121: 是回文
    2231322: 是回文
    */