Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ,

i want know the how to reverse the words in a string.After that i want know the i arrage the reverse words in a assending order.

What I have tried:

Actually i tried with predefind methods,but i dont want that.please help this without using predefined methods.

const string s1 = "Bill Gates is the richest man on Earth";
const string s2 = "Srinivasa Ramanujan was a brilliant mathematician";

string rev1 = Program.ReverseWords(s1);
Console.WriteLine(rev1);

string rev2 = Program.ReverseWords(s2);
Console.WriteLine(rev2);


Console.ReadLine();
Posted
Updated 10-Aug-16 23:49pm
Comments
Karthik_Mahalingam 11-Aug-16 5:52am    
what is your expected output for ?
const string s1 = "Bill Gates is the richest man on Earth";
const string s2 = "Srinivasa Ramanujan was a brilliant mathematician";

1 solution

C#
public static string ReverseString(string s)
  {
  char[] arr = s.ToCharArray();
  Array.Reverse(arr);
  return new string(arr);
  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900