Home > Backend Development > C#.Net Tutorial > Reverse words in given string in C#

Reverse words in given string in C#

WBOY
Release: 2023-09-04 11:53:07
forward
1283 people have browsed it

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

Assume the following is the string -

Welcome
Copy after login

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

emocleW
Copy after login

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);
   }
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template