以单词为单位对字符串进行翻转(用C#编写,但不用其中的库函数)

//以单词为单位对字符串进行翻转,先按照字母进行翻转,然后按照单词进行翻转             string str1 = "12345     67890";             string str2 = "";             string str3 = "";             for (int o = str1.Length - 1; o >= 0; o--)                 str2 += str1[o];//按字母翻转             char[] chArr = new char[str1.Length];             int i = 0;             int j = 0;             int index = 0;             while (index < str2.Length-1)             {                 if (str2[index] == ' ')                 {                     j = index - 1;                     while (i <= j)                     {                         chArr[i] = str2[j];                         chArr[j] = str2[i];                         i++;                         j--;                     }                     index++;                     i = index;                 }                 else                 {                     index++;                 }             }             if (index == str2.Length - 1)             {                 j = index;                 while (i <= j)                 {                     chArr[i] = str2[j];                     chArr[j] = str2[i];                     i++;                     j--;                 }             }             for (int k = 0; k < str2.Length; k++)                 str3 += chArr[k].ToString();//按照单词翻转             Console.WriteLine("The reverse letter by letter of   {0}   is   {1}", str1, str2);             Console.WriteLine("The reverse word by word of   {0}   is   {1}", str1, str3);             Console.ReadLine();

转载于:https://www.cnblogs.com/xiongxuanwen/archive/2008/03/19/1992394.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值