字符串短的话,可以这样:
string Str = "I am a boy";
string StrChanged = string.Empty;
string[] Arr = Str.Split(' ');
for (int i = Arr.Length; i > 0; i--)
{
StrChanged += Arr[i - 1] + " ";
}
Console.WriteLine(StrChanged.Trim());
Console.Read();
如果比较长,改用StringBuilder效率会高一些:
string Str = "I am a boy";
StringBuilder StrChanged = new StringBuilder(512);
string[] Arr = Str.Split(' ');
for (int i = Arr.Length; i > 0; i--)
{
StrChanged.Append(Arr[i - 1]).Append(" ");
}
Console.WriteLine(StrChanged.ToString().Trim());
Console.Read();
丁学
|
专家六级
|园豆:18730
|
2008-03-08 10:18