A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 张向阳 中级黑马   /  2012-12-14 21:15  /  1619 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

               string str = "Nothing is difficult,  if you put your heart into it";
            string[] strs = str.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);//切除空格
            for (int i = 0; i < strs.Length; i++)
            {
                char[] chs = strs.ToCharArray();//用far循环将每一个字符串转化成字符数组
                for (int j = chs.Length - 1; j >= 0; j--)
                {
                    Console.Write(chs[j]);//再嵌套一个循环反向输出
                }
                Console.Write(" ");//每循环完一个单词,加一个空格
            }
            Console.WriteLine();
            Console.ReadKey();

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

4 个回复

倒序浏览
            string str = "Nothing is difficult, if you put your heart into it";
            string[] strs = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);//切除空格
            Array.Reverse(strs);  //我的只是直接调用数组的反转方法而已,其他的和你的差不多
            for (int i = 0; i < strs.Length; i++)
            {
                Console.Write(" {0}",strs);
            }
            Console.ReadKey();

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

回复 使用道具 举报
本帖最后由 Mayi 于 2012-12-15 00:27 编辑

先按照空格Split,然后对每个单词Reverse,多次迭代一大坨代码...

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

回复 使用道具 举报
罗代势 发表于 2012-12-15 00:11
string str = "Nothing is difficult, if you put your heart into it";
            string[] ...

学习了~~~
回复 使用道具 举报
Mayi 发表于 2012-12-15 00:22
先按照空格Split,然后对每个单词Reverse,多次迭代一大坨代码...

学习了~~~~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马