English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i have this textbox and when use types some lets say ''REVERSE'' THAN on the label box it should show ''ESREVER'' just excat revese of that word . how can i do it? plz dont link me to different website i just want the code.

2007-01-28 12:47:38 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

Or you can just make a recursive call, this is short and pretty.

public static string Reverse(string str)
{
// Recursion Termination
if(str.Length==1)
{
return str;
}
else
{
// Now store the first character at the end of the string Thats how you reverse
return Reverse( str.Substring(1) ) + str.Substring(0,1);
}
}


Taken from and adapted from a CString library. I use CString whenever I can, but this method works great. Recursive call that reverses a String in C#.

Good Luck

2007-01-29 09:14:59 · answer #1 · answered by ? 6 · 0 0

You want to know how to make a text box - so that when a user types a word like "REVERSE" in the box - the box will show the word in the exact reverse - for example "ESREVER"

2007-01-28 13:03:38 · answer #2 · answered by birdwatcher 4 · 0 3

string myInput = textbox.text;
myInput = myInput.Trim();
int myInputLength = myInput.Length();
myInputLength -= 1;
int x;
string myOutput;

for(x = myInputLength; x > -1; x--) {
myOutput += myInput.Substring(x, 1);
}

Console.Write(myOutput);

EDIT:

There is no .NET String member named Reverse, contrary to what the previous answer said.

There is a Reverse member in Array, so you could send the string to a character array, reverse that array, then rejoin the array to a string.

2007-01-28 14:27:11 · answer #3 · answered by Anonymous · 1 1

I know in VB.NET the string object has a .Reverse
function, which makes it simple. Check that out in C#.

2007-01-28 13:07:49 · answer #4 · answered by Anonymous · 0 2

fedest.com, questions and answers