(C#)单词反转 位置不变 e.g., Welcome to my blog! -> emocleW ot ym !golb
2010-12-08 12:46
579 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { public static string ReverseString(string input) { string output = null; if (input != null) { for (int i = 0; i < input.Length; i++) { output = input[i] + output; } } return output; } public static string ReverseWord(string input) { string output = null; if (input != null) { string[] words = input.Split(' '); foreach (string word in words) { output = output + ReverseString(word) + " "; } output = output.TrimEnd(' '); } return output; } static void Main(string[] args) { string a = null; Console.WriteLine(ReverseString(a)); Console.WriteLine(ReverseWord(a)); a = string.Empty; Console.WriteLine(ReverseString(a)); Console.WriteLine(ReverseWord(a)); a = "asfddsaf123_*(*%^$afd"; Console.WriteLine(ReverseString(a)); Console.WriteLine(ReverseWord(a)); a = "Welcome to my blog!"; Console.WriteLine(ReverseString(a)); Console.WriteLine(ReverseWord(a)); } } }
相关文章推荐
- 单词反转 eg. Welcome to my house!-> emoclew ot ym esuoh!
- welcome to my scala and spark blog! Let's go!
- Welcome to My Blog
- Friends, Welcome to my blog!
- C++ -> C#: What You Need to Know to Move from C++ to C#
- hello,welcome to my blog
- Welcome to visit My Blog
- restart my csdn blog:>)
- Welcome to my blog.
- <img src=1 onerror="alert('Welcome to My CSDN Blog');">
- Welcome to my blog
- Welcome To My Blog!
- Hi, welcome to my blog
- welcome to my new blog !
- Welcome To My Blog
- welcome to my new blog
- My csdn blog is setup today, welcome to be here.
- welcome to my Blog.
- 编程之美的2.17,数组循环移位 & 字符串逆转(反转) Hello world Welcome => Welcome world Hello
- Welcome to my blog http://bobosiris.spaces.live.com/