欢迎光临
我们一直在努力

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

建站超值云服务器,限时71元/月

 public static int Main(string[] args)
        {
   


            Console.WriteLine(“============================”);
            string s = “im 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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 利用正则表达式来反转一句话,以单词为单位_c#应用
分享到: 更多 (0)