日期:2014-05-18  浏览次数:21093 次

输入一串字符,如"this is test",将这串字符反向输出,也就是"test is this",请问大哥大姐怎么去实现它,请贴出代码,谢谢.
输入一串字符,如"this is test",将这串字符反向输出,也就是"test is this",请问大哥大姐怎么去实现它,请贴出代码,谢谢

------解决方案--------------------
这样试试看:

string str = "this is test";
char[] cs = str.ToCharArray();
Array.Reverse(cs);
str = new string(cs);

Console.WriteLine(str);
------解决方案--------------------
string str = "this is test";
string[] sss = str.Split(' ');
Array.Reverse(sss);
然后输出sss
------解决方案--------------------
以空格split后,再for倒着输出
------解决方案--------------------
如果是颠倒单词则参考如下:
C# code
string s = "this is test";
string t = string.Empty;
foreach (string v in s.Split(new char[] { ' ' },
    StringSplitOptions.RemoveEmptyEntries))
    t = v + " " + t;
t = t.Trim();
Console.WriteLine(t);

------解决方案--------------------

string str = "this is test"; 
string[] strs = str.Split( ' ');
Array.Reverse(strs);
str = string.Join(" ",strs);
Response.Write(str);