Introduction
In this article, we are going to explore how to reverse each word of the given string.
Example
Input: This is Kirtesh Shah
Result: sihT si hsetriK hahS
This is an essential technical interview question that may be posed to beginner, intermediate, and experienced candidates.
We previously covered how to reverse a string in the last article,
- How to Reverse Number in C#
- How to Reverse a String in C#
- Palindrome String Program in C#
- Palindrome Number in C#
- How to reverse order of the given string
Let’s start.
Reverse each word the give String
First create Asp.NET Core Console application and write the below code in the program.cs file.
Console.WriteLine("Enter a string");
var str = Console.ReadLine();
var strarray = str.Split(" ");
List<string> lst = new();
foreach (var item in strarray)
{
lst.Add(new string(item.Reverse().ToArray()));
}
var reverseOrder = String.Join(" ", lst);
Console.WriteLine($"{reverseOrder}");
Console.ReadLine();
Output
That’s all for this article. Hope you enjoy this article and learn something new.