Results 1 to 5 of 5

Thread: Find the first 'space' in a string

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265

    Post

    I want to be able to separate a string into two further strings - probably easiest by finding the first 'space' in the string.

    Eg. the string contains a website and a description. I need to be able to split them into two strings:
    http://www.yahoo.co.uk UK version of this popular search engine http://www.bbc.co.uk The BBC's own Internet home page http://www.knowsley.gov.uk Knowsley MBC's home on the 'Net

    Hope someone can help

    Simon

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Post

    Use the InStr function to determine the location of the space. InStr finds the first occurence of a specified character in a string.

    Private Sub Command1_Click()

    Dim String1, String2, String3 As String

    String1 = "http://www.yahoo.co.uk UK version of this popular search engine"

    String2 = _
    Left(String1, InStr(String1, " "))
    String3 = _

    Right(String1, Len(String1) - InStr(String1, " "))

    End Sub



    ------------------
    Andrew Nerney
    Hapless Programmer
    [email protected]

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Post

    you can always used the Instr command like

    Dim Pos%, MyStr1$, MyStr2$
    Pos% = Instr(1,"http://www.bbc.co.uk <Description>"," ", vbBinaryCompare)

    if Pos% <> 0 then
    MyStr1$ = left("http://www.bbc.co.uk <Description>", Pos%-1)
    MyStr2$ = Mid("http://www.bbc.co.uk <Description>",pos%+1)
    End IF

    ____________________
    Chris.C
    [b]Software Engineer[/]
    [email protected]

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265

    Post

    Thank you gents!

    Simon

  5. #5
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Post

    No hay problema, simonp! And ChrisC - looks like great minds think alike. Same function and posted the exact same minute! LOL!



    ------------------
    Andrew Nerney
    Hapless Programmer
    [email protected]

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