Dipendra Singh Shekhawat
How to reverse each word in a string using c#?
By Dipendra Singh Shekhawat in C# on Apr 06 2016
  • Ayappan Alagesan
    Feb, 2017 12

    string.reverse() can be used.

    • 0
  • Dipendra Singh Shekhawat
    Apr, 2016 6

    String to be reversed:DS tech blogOutput or the reversed string:SD hcet golbHow to reverse each word in a string using c#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; Explanation for the above code:Split the input string using a single space as the separator.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.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS