Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi frnds,

How to reverse a string in asp.net c#.

I have two textboxes and button.

In First Textbox i will enter the text and clicks on button. and in second textbox it should be reverse.

Please help me, how to reverse the string.

Thanks.
Posted
Comments
Pheonyx 25-Jun-13 3:58am    
This sort of question shows pure laziness.
Firstly there is the poor spelling and grammar (I do not claim to be good at either but I at least spell check my questions). Secondly, there is the fact you clearly have not bothered to do any research at all.

Reversing a string is a very basic process and a simple Google search would have shown up a variety of different approaches you could try. But no, you could not even be bothered with that instead you post in a forum and hope that someone will do the work for you.

If you take the basic premise of what you are trying to do you could simply do a reverse for loop through the string and add the letters to the second text box one at a time. Or you could use built in functions as in "Solution 1".

Then you could look at being really fancy and using extension methods to make your code look good.

In future, try doing some research, people on this site are more than happy to help, but are much more inclined to help you more a) if you look to have actually tried something. b) have read the posting guidelines.

If Solution 1 has met your requirements please mark it as selected and rate it with the stars so that Orcun gets recognition.
Adarsh chauhan 25-Jun-13 7:24am    
sorry to say but i looks like you have not tried at your own level.you could get the answer simply by goggling...

1 solution

Here is your answer to your homework..
C#
public static string Reverse( string s )
{
    char[] charArray = s.ToCharArray();
    Array.Reverse( charArray );
    return new string( charArray );
}
 
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