Home  >  Article  >  Backend Development  >  Reverse words in given string in C#

Reverse words in given string in C#

WBOY
WBOYforward
2023-09-04 11:53:071266browse

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

Assume the following is the string -

Welcome

After flipping the string, the words should be visible like −.

emocleW

Use reverse() method and try the following code to reverse the words in the string -

Example

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

The above is the detailed content of Reverse words in given string in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Byte structures in C#Next article:Byte structures in C#