String to be reversed:
DS tech blog
Output or the reversed string:
SD hcet golb
Our Logic in CSharp (C#):
- string input = "DS tech blog";
- string result = string.Join(" ", input
- .Split(' ')
- .Select(x => new String(x.Reverse().ToArray())));
- Console.WriteLine(result);
Remember to include the below using statements:
- using System;
- using System.Linq;
- Split() method for returning a string array that contains each word of the input string.
- Select method for constructing a new string array, by reversing each character in each word.
- Join method for converting the string array into a string.
References:
You can read about all these methods in detail on MSDN. Below are the links for your reference.
What do you think?
Dear Reader,
If you have any questions or suggestions please feel free to email us or put your thoughts as comments below. We would love to hear from you. If you found this post or article useful then please share along with your friends and help them to learn.
Happy Learning.

Vinay KPosted Mar 17, 2017, 6:06 AM
String result = string.Join(" ", input.Split(' ').Select(x => new String(x.Reverse().ToArray())).ToArray());
Vinay KPosted Mar 17, 2017, 6:06 AM
It's worked for me.
Vinay KPosted Mar 17, 2017, 6:05 AM
I am using .NET 3.5,l need to convert the reversed sequence to an array too.
Vinay KPosted Mar 17, 2017, 6:01 AM
Using System;using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string input = "DS tech blog"; string result = string.Join(" ", input.Split(' ').Select(x => new String(x.Reverse().ToArray()))); Console.WriteLine(result); Console.ReadLine(); } } }
Vinay KPosted Mar 17, 2017, 5:57 AM
Error 1 The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments
Dhruv MauryaPosted Apr 2, 2016, 8:23 AM
Nice ..
Dipendra ShekhawatPosted Mar 29, 2016, 11:00 PM
Thanks Jaco Zwarts !
Jaco ZwartsPosted Mar 29, 2016, 12:15 PM
Nice, Thanks for sharing