Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

quick vb question

  • 26-07-2004 03:40PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 1,022 ✭✭✭[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, Registered Users 2 Posts: 937 ✭✭✭Diddy Kong


    cheers, exactly what i was lookin for


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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