Reverse logic for string

If we pass the ref type of string as a parameter.
It will the method reverseString will reverse your string
The below code is used to reverse your string


public void reverseString(ref string MyString) {
string tempStr = "";
int i, j;

Console.WriteLine("Reversing your string");
for(j=0, i=MyString.Length-1; i >= 0; i--, j++)
tempStr += MyString[i];

MyString = tempStr;
}


Code Explanation

1. Pass the ref type string as a parameter
2. create the variables tempstr,i,j
3. use the for loop logic as above you can get the reversed string as out put


By
Nathan


Comments

Author: Fool To Code24 Oct 2009 Member Level: Gold   Points : 1

yes its a good logic and in vb.net we can use the vb inbuilt function:

MessageBox.Show(StrReverse("deepak"))

it will show: kapeed

regards
FoolToCode



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: