日期:2014-05-20 浏览次数:20481 次
using System; using System.Text.RegularExpressions; class Demo { static string ReverseAlpha(string s) { string t = Regex.Replace(s, "[^A-Za-z]", ""); char[] c = s.ToCharArray(); for (int i = 0, j = t.Length - 1; i < c.Length; i++) { if (Char.IsLetter(c[i])) // c[i] >= 'A' && c[i] <= 'Z' || c[i] >= 'a' && c[i] <= 'z' { c[i] = t[j]; j--; } } return new string(c); } static void Main() { string s = "1w4rt,5t7?9u"; Console.WriteLine(s); string t = ReverseAlpha(s); Console.WriteLine(t); } }