Hi all,
I have a string like
string str = "I love Microsoft very much";
and then I want output as follows (beware of uppercase and lowercase):
much very Microsoft love I
How do I do this in C# ?
waiting for your reply.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Feb 23, 2012, 4:17 AM EST
Pramod Kumar NandagiriRank #6,963 · 252 reputationPosted Feb 23, 2012, 6:49 AM EST
string s2=string.Empty;
for (int i = str.Length; i > 0; i--)
{
s2 += str[i-1];
}
Response.Write(s2);
VulpesRank #55 · 29.2K reputationPosted Feb 23, 2012, 6:55 AM EST
Also mine won't work either if word separators other than spaces are to be allowed (comma, period etc), though it's not difficult to allow for this.
Pramod Kumar NandagiriRank #6,963 · 252 reputationPosted Feb 23, 2012, 7:08 AM EST
Sorry i didn't read the post correctly...
SenthilkumarRank #387 · 6.5K reputationPosted Feb 23, 2012, 6:30 PM EST
This will do the reverse of the words....
string str = "I love Microsoft Very much";
string[] _words = str.split(" ");
string strReverse = string.empty;
for(int i=_Words.Length;i>0;i--)
{
strReverse += _words[i] + " ";
}
Console.WriteLine(strReverse);