hi! i wanted to make a program to reverse the users input i.e-
"This is c# example" to "example c# is the"
any idea how to go about doing this ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jan 21, 2015, 4:42 PM
Noaman KhalilPosted Jan 21, 2015, 9:45 AM
Khargesh RajputPosted Jan 21, 2015, 6:55 AM
Implement properly
Manish Kumar ChoudharyPosted Jan 21, 2015, 6:15 AM
How you implement my code in your project. It's working fine.
Noaman KhalilPosted Jan 21, 2015, 5:49 AM
Khargesh RajputPosted Jan 20, 2015, 11:27 PM
string[] words = s.Split(' ');
Array.Reverse(words);
lblMsg.Text= string.Join(" ", words);
output: example c# is the
Manish Kumar ChoudharyPosted Jan 20, 2015, 11:22 PM
Try This.
protected void Page_Load(object sender, EventArgs e)
{
string Name = "This Is Manish";
Response.Write(Name + "
");
Response.Write(Reverse(Name));
}
public string Reverse( string s)
{
var result = s.Split(' ');
return string.Join(" ", result.Reverse());
}
o/p:- Manish Is This
Akhil GargPosted Jan 20, 2015, 11:05 PM
Hi Noaman,
Just split that input into array of string and then display that array in reverse order You can directly use split function to split string based on ' ' this character