Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

quick vb question

Options
  • 26-07-2004 3:40pm
    #1
    Registered Users Posts: 937 ✭✭✭


    hi, i have a string, eg "im a string @1234 @4321", i want to seperate the string, eg string1="im a string" string2="@1234 @4321", thought about an array, any suggestions on a function or work round.....


Comments

  • Registered Users Posts: 1,023 ✭✭✭[CrimsonGhost]


    Sub blah()
        Dim str As String
        Dim leftStr As String
        Dim rightStr As String
        
        Dim pos As Integer
        str = "im a string @1234 @4321"
        pos = InStr(str, "@")
        
        leftStr = Left(str, pos - 1)
        rightStr = Mid(str, pos)
        
        MsgBox str
        MsgBox leftStr
        MsgBox rightStr
    End Sub
    

    Not perfect. You'll still have a space on the end of leftStr, so you may want to strip that first. I tried that as VBA, works fine though, so should be the same in VB.


  • Registered Users Posts: 937 ✭✭✭Diddy Kong


    cheers, exactly what i was lookin for


  • Registered Users Posts: 354 ✭✭Mick L


    Originally posted by [CrimsonGhost]
        ...
        leftStr = [b]Trim([/b]Left(str, pos - 1)[b])[/b]
        ...
    

    Not perfect. You'll still have a space on the end of leftStr

    The trim() function will sort out any spaces


  • Registered Users Posts: 1,268 ✭✭✭hostyle


    You could also use split


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Originally posted by hostyle
    You could also use split
    Split is to be found in VBScript and not VB proper (althou in fairness dbfarrell has not specified which they're using). VB/VBS/VBA really sucks at array handling, TBH.


  • Advertisement
  • Registered Users Posts: 950 ✭✭✭jessy


    split can be found in VB 6 although I’m not sure what you mean by VB proper


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Originally posted by jessy
    split can be found in VB 6 although I’m not sure what you mean by VB proper
    Upps... didn't know VB6 had implemented it - VB5 dosen't :o


Advertisement