Results 1 to 15 of 15

Thread: string reverse?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    string reverse?

    I am having string issue. I am trying reverse the string, but cannot seem to accomplish.

    Scenario:

    The string is dynamic - def, abc - I want the out put as message box to be abc def
    If the string is def, abc 123 - I want the out put to be abc 123 def

    Is it posssible to reverse string with vb6?

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: string reverse?

    Yes it is possible. In this case you may want to use the Split() function to break the string into an array using the space as a seperator then loop through the resulting array back to front appending the items to a new string.

    Something like this for example
    Code:
    Private Sub Command1_Click()
    Dim MyString As String
    Dim MyArray() As String
    
    MyString = "def, abc 123"
    
    MyArray = Split(MyString, " ")
    MyString = ""
    Dim x As Integer
     For x = UBound(MyArray) To 0 Step -1
        MyString = Trim(MyString & " " & MyArray(x))
    Next
    
    MsgBox MyString
    End Sub
    Last edited by DataMiser; Feb 7th, 2013 at 04:17 PM.

  3. #3
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: string reverse?

    That's not really reversing a string. A reversed string would be if def = abc 123 then reversed is 321 cba

    What you're asking is how to switch each element around.

    Dim a() As String
    Dim s as string

    a = Split(def,Space(1))

    s = a(1) & Space(1) & a(0)
    Last edited by jmsrickland; Feb 7th, 2013 at 04:20 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: string reverse?

    StrReverse reverses the character order of the specified string, but that doesn't seem to be what you need.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: string reverse?

    Oh yes sorry. Thanks for giving me some insights. I found this :

    http://www.devx.com/vb2themax/Tip/19218

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: string reverse?

    see post number 2. I edited it to add a simple example

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: string reverse?

    Quote Originally Posted by vbbit View Post
    I am having string issue. I am trying reverse the string, but cannot seem to accomplish.

    Scenario:

    The string is dynamic - def, abc - I want the out put as message box to be abc def
    If the string is def, abc 123 - I want the out put to be abc 123 def

    Is it posssible to reverse string with vb6?
    Are you sure? I would think you want 123 abc def


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  8. #8
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: string reverse?

    is it me or there is a comma??
    i would split with
    dim a() as string
    a = split(string,", ")
    string = a(1) & Space(1) & a(0)
    Last edited by Max187Boucher; Feb 7th, 2013 at 05:22 PM.

  9. #9
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: string reverse?

    I thought def was the name of the string, lol. I see now it is just another element. So, yes, split on comma


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: string reverse?

    Aye Max, Based upon what OP SAYS he wants, then the comma would be used to split the string into TWO strings, not three....sometimes hard to determine JUST what an OP wants.

  11. #11
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: string reverse?

    hey sam sorry i dont get the three strings?? maybe i am not reading your post properly

  12. #12
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: string reverse?

    Hey Max, no, I just saw that jms and datam might have misread OPs intent....(as did I when first looking at it). They both suggested (I THINK) to split the string into three strings, not two. YOUR post is correct (I think) as to what OP wants.

  13. #13
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: string reverse?

    ahh yes with the split space it does make three strings

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: string reverse?

    Who knows... the way the OP is worded is very difficult to be sure.

  15. #15
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: string reverse?

    Ayup

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