Results 1 to 12 of 12

Thread: Reverse String

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    13

    Question Reverse String

    I know this may seem pretty simple to most but I need to reverse a string. So like if the user types "WX YZ" I want the output to be "ZY XW" Is there a way to do that using a loop?

    Thanks in advance.

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Reverse String

    VB Code:
    1. Dim s As String = "This is the string"
    2.         Dim ReverseString As String = ""
    3.         For i As Integer = s.Length - 1 To 0 Step -1
    4.             ReverseString &= s.Substring(i, 1)
    5.         Next
    that should do it, although there may be a better way using the .Reverse property of arrays
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Reverse String

    If you want to do it without a loop...

    VB Code:
    1. Dim h As String = "Hello"
    2. Dim chars As Char() = h.ToCharArray
    3. Array.Reverse(chars)
    4. h = New String(chars)
    I don't live here any more.

  4. #4
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Reverse String

    i though you could do it w/o a loop, i just didn't know how to get from the char array back to a string. cool
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  5. #5
    New Member
    Join Date
    Feb 2005
    Location
    Manchester, England
    Posts
    4

    Re: Reverse String

    Hi,

    Wont something like the following do it:

    Label1.Text = StrReverse(TextBox1.Text)

    HTH

    Alan

  6. #6
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    Re: Reverse String

    That shoud be deprecated these days.
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  7. #7
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Reverse String

    Quote Originally Posted by DNA7433
    That shoud be deprecated these days.
    just curious, but why?
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  8. #8
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Reverse String

    Quote Originally Posted by kebo
    just curious, but why?
    Because its an old vb6 function you should always use .net .
    "The dark side clouds everything. Impossible to see the future is."

  9. #9
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Reverse String

    Quote Originally Posted by Asgorath
    Because its an old vb6 function you should always use .net .
    is it not managed by the CRL?
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  10. #10
    Addicted Member corwin_ranger's Avatar
    Join Date
    Sep 2004
    Location
    CT
    Posts
    198

    Question Re: Reverse String

    Is there a guide for these old functions somewhere that points to the appropriate .NET version? For example, I'm being taught in class to use the IsNumeric() function to do some basic validation. Is this a VB6 hold-over? If so, what's the .NET equivalent? I'd love to find a link or document somewhere so that I can lookup whether or not a function/method is a VB6 holdover and find the replacment .NET function/method. I don't really have a frame of reference since I'v done virtually no VB6 programming and what little bit I HAVE done was over 6 years ago.

    Thanks,

    Steve
    Last edited by corwin_ranger; Apr 1st, 2005 at 11:22 AM.

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Reverse String

    Quote Originally Posted by kebo
    is it not managed by the CRL?
    no it is.. but its basically included in the framework for backwards compatibility to help VB6 programmers upgrade apps easier... to make the VB6 to VB.NET upgrade wizard produce less errors you have to fix.. etc...

    generally the .net ways you can accomplish the same task tend to be better on performance than the VB6 compatibilty functions (even though I will admin some will show little to no difference over all, possibly in some massive loops or complex coding)

    but like I said before, its better just from a .net programmer standpoint if you need to work on C# or something, it will be much easier if you stick to the core of the .net framework

  12. #12
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Reverse String

    Quote Originally Posted by kleinma
    generally the .net ways you can accomplish the same task tend to be better on performance than the VB6 compatibilty functions (even though I will admin some will show little to no difference over all, possibly in some massive loops or complex coding)
    this is probably true but with out taking performance into account,
    VB Code:
    1. Label1.Text = StrReverse(TextBox1.Text)
    is easier to read and code than
    VB Code:
    1. Dim chars As Char() = TextBox1.Text
    2. Array.Reverse(chars)
    3. Label1.Text = New String(chars)
    Having said that though, I would still prefer to do it the .net way.
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width