首页  >  文章  >  后端开发  >  C# 中给定字符串中的单词反转

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

WBOY
WBOY转载
2023-09-04 11:53:071220浏览

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);
   }
}

以上是C# 中给定字符串中的单词反转的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除