C# 中给定字符串中的单词反转

来源:这里教程网 时间:2026-02-21 16:22:34 作者:

c# 中给定字符串中的单词反转

假设以下是字符串 -

Welcome

翻转字符串后,单词应该像 − 这样可见。

emocleW

使用reverse()方法并尝试以下代码来反转字符串中的单词 -

示例

using System;
using System.Linq;
class Demo {
   static void Main() {
      string str = "Welcome";
      // reverse the string
      string res = string.Join(" ", str.Split(' ').Select(s => new String(s.Reverse().ToArray())));
      Console.WriteLine(res);
   }
}

相关推荐