字符串里面的单词反转
2013-05-02 11:16
260 查看
字符串里面的单词反转,可以用string/stringBuilder
View Code
View Code
using System; using System.Collections; using System.Text; namespace InsertionSorter { public static class InsertionSorter { public static string ReverseString(string str) { string result = null; string[] s = str.Split(' '); for (int i = 0; i < s.Length; i++) { for (int j = s[i].Length - 1; j >= 0; j--) { result += (s[i])[j]; } result += " "; } return result; //Result: siht si a .tset } public static string StrReverse(string str) { StringBuilder sb = new StringBuilder(); string[] s = str.Split(' '); for (int i = 0; i < s.Length; i++) { sb.Append(Reverse(s[i]) + " "); } return sb.ToString(); //Result: siht si a .tset } private static string Reverse(string str) { StringBuilder sb = new StringBuilder(); for (int i = str.Length - 1; i >= 0; i--) { sb.Append(str[i]); } return sb.ToString(); } } public class MainClass { public static void Main() { string result = null; string thisString = "this is a test."; InsertionSorter.ReverseString(thisString); result = InsertionSorter.StrReverse(thisString); Console.WriteLine(result); } } }
相关文章推荐
- 将字符串按照单词完全反转-大公司面试题
- python文本 字符串逐字符反转以及逐单词反转
- 古娜拉黑暗之神(编程实现字符串中各单词的反转)
- 以单词为单位,对字符串进行反转
- 字符串反转--句子反转和单词反转
- (C#) 反转字符串,反转一个句子中单词。
- 按单词反转字符串
- 以单词为单位,对字符串进行反转
- 剑指Offer 42反转单词顺序 vs左旋转字符串
- Java实现字符串中的单词反转
- 【字符串1】反转单词顺序
- php字符串按照单词进行反转的方法
- 字符串单词反转
- C语言来实现字符串反转 只有单词顺序反转,单词里的字母不反转
- 反转字符串中的单词顺序
- (String)将一个String里面的单词反转
- 【转】按单词反转字符串
- 第六题 反转字符串,单词内部顺序不变
- 【LeetCode在线编程记录-1】字符串按单词反转
- 面试题42反转单词顺序VS左旋字符串(循环左移字符串)