利用正则表达式来反转一句话,以单词为单位

10/20/2006来源:C#应用人气:11130

 public static int Main(string[] args)
        {
   

            Console.WriteLine("============================");
            string s = "i'm a student,my name is yuhong!ok!!!";
 
            string[] sArray = System.Text.RegularExPRessions.Regex.Split(s, @"[^\w]+", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            //记录标点符号
            string[] sArray2 = System.Text.RegularExpressions.Regex.Split(s, @"[\w]+",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            int start = 0;
            int end = sArray.Length - 1;
            while (start<end)
            {
                string tmp = sArray[start];
                sArray[start] = sArray[end];
                sArray[end] =tmp;
                start++;
                end--;
            }


            start = 0;
            end = sArray2.Length - 1;
            while (start < end)
            {
                string tmp = sArray2[start];
                sArray2[start] = sArray2[end];
                sArray2[end] = tmp;
                start++;
                end--;
            }
            // s=string.Join(" ", sArray);
            string result = "";
            for (int i2 = 0; i2 < sArray.Length; i2++)
            {
                result += sArray[i2] + sArray2[i2];
            }


            s = result;
            Console.WriteLine(s);
            //Console.WriteLine("============================");
            //string str1 = "我**是*****一*****个*************教*****师";
            //string[] str2 = System.Text.RegularExpressions.Regex.Split(str1, @"[*]+");
            //foreach (string iss in str2)
            //    Console.WriteLine(iss.ToString());
            return 0;
        }
http://www.cnblogs.com/meiwn/archive/2006/10/19/533587.html