.net

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);
}
}

private string reverse(string src)
        {
           
char[] s = src.ToCharArray();
           
char c='\0';
           
int i = 0;
           
int j = s.Length - 1;
           
for (; i < j; )
               
if (s[i] >= 65 && s[i] <= 90 || s[i] >= 97 && s[i] <= 122)
                   
if (s[j] >= 65 && s[j] <= 90 || s[j] >= 97 && s[j] <= 122)
                    { c
= s[i]; s[i] = s[j]; s[j] = c; i++; j--; }
                   
else
                        j
--;
               
else
                   
if (s[j] >= 65 && s[j] <= 90 || s[j] >= 97 && s[j] <= 122)
                        i
++;
                   
else
                    { i
++; j--; }
           
return new string(s);
        }

你可能感兴趣的:(.net,职场,休闲)