Reverse word of full sentence

c#

Solution

You would need to split the string into words and the reverse those instead of reversing the characters:

text = String.Join(" ", text.Split(' ').Reverse())

In framework 3.5:

text = String.Join(" ", text.Split(' ').Reverse().ToArray())

In framework 2.0:

string[] words = text.Split(' ');
Array.Reverse(words);
text = String.Join(" ", words);

Problem

I want to print string in reverse format: Input: `My name is Archit Patel` Output: `Patel Archit is name My`. I've tied the following but it displays as `letaP tihcrA si eman ym`. ``` public static string ReverseString(string s) { char[] arr = s.ToCharArray(); Array.Reverse(arr); return new string(arr); } ```

Original source