课上练习2:接收用户输入的一句英文,将其中的单词以反序输出。"hello c sharp"→"sharp c hello"
string str = "hello c sharp";
string[] strNew = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < strNew.Length / 2; i++)
{
string temp = strNew[i];
strNew[i] = strNew[strNew.Length - 1 - i];
strNew[strNew.Length - 1 - i] = temp;
}
Split()分割字符串,将分割后的字符串返回成数组
于 2023-04-10 13:31:58 首次发布