Results 1 to 5 of 5

Thread: Code to display input in reverse

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Answers
    5

    Code to display input in reverse

    Dear fnds,
    i have 2 text boxes 1 button, my question is i am entering (example 123 or abc ) in 1st textbox, when i click button then ( 321 or cba ) will dispaly in 2nd textbox.

    please tell how to write code for this.

    cheers


  2. #2
    Junior Member
    Join Date
    Sep 2007
    Answers
    10

    Re: Code to display input in reverse

    use reverse function


  3. #3
    Junior Member
    Join Date
    Nov 2007
    Answers
    5

    Re: Code to display input in reverse

    Quote Originally Posted by bsrreddy View Post
    Dear fnds,
    i have 2 text boxes 1 button, my question is i am entering (example 123 or abc ) in 1st textbox, when i click button then ( 321 or cba ) will dispaly in 2nd textbox.

    please tell how to write code for this.

    cheers
    U can go this way
    int a = Textbox1.Text.Length;
    string b = "";
    for(int i=a;i>0;i--)
    {
    b = b+""+Textbox1.Text.Substring(i-1, 1).ToString();
    }
    Textbox2.Text = b;


  4. #4
    Junior Member
    Join Date
    Nov 2007
    Answers
    9

    Lightbulb Re: Code to display input in reverse

    I could not find the Reverse function . Though created my own function using a for loop.

    private string reverse(string str)
    {
    string rev = string.Empty;
    for (int i=str.Length-1; i>=0;i--)
    {
    rev += str[i];
    }
    return rev;

    }

    try using this.


  5. #5
    Junior Member
    Join Date
    Jul 2008
    Answers
    7

    Re: Code to display input in reverse

    Quote Originally Posted by bsrreddy View Post
    Dear fnds,
    i have 2 text boxes 1 button, my question is i am entering (example 123 or abc ) in 1st textbox, when i click button then ( 321 or cba ) will dispaly in 2nd textbox.

    please tell how to write code for this.

    cheers
    string s=textBox1.Text;//entered in this textbox1 as 123
    int p=s.Length;
    if(p!=0)
    {
    string k;
    for(int t=1;t<=p;t++)
    {
    k=s.Substring(p-t);
    textBox2.Text+=k;//you get the reverse order in this text box2
    int q=s.Length;
    int w=0;
    string r=s.Remove(q-1,w+1);
    s=r;
    }
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact