Results 1 to 4 of 4

Thread: [RESOLVED] Help with delimiters in a string

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Location
    San Marcos, TX
    Posts
    177

    Resolved [RESOLVED] Help with delimiters in a string

    If I have the following variables and string:

    Dim line, type, id, filename As String
    line= "p,12345,nothing.jpg"

    How can I do the following?

    type=p
    id=12345
    filename=nothing.jpg

    So how can I split this string up into those smaller strings?

    Thanks!

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Help with delimiters in a string

    You can use the Split function. Something like this:

    Code:
            Dim line, type, id, filename As String
            Dim values() As String
            line = "p,12345,nothing.jpg"
            values = line.Split(","c)
    
            If values.Length = 3 Then
                type = values(0)
                id = values(1)
                filename = values(2)
            End If

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Location
    San Marcos, TX
    Posts
    177

    Re: Help with delimiters in a string

    Thanks, it worked great!

  4. #4
    New Member
    Join Date
    Mar 2010
    Posts
    10

    Re: [RESOLVED] Help with delimiters in a string

    Code:
            Dim sData As String = "p,12345,nothing.jpg"
            Dim sInfo() As String = Split(sData$, ",")
            Dim sType, sID, sFileName As String
    
            sType$ = sInfo$(0)
            sID$ = sInfo$(1)
            sFileName$ = sInfo$(2)
    
            MsgBox("Type: " & sType$ & vbCrLf & _
                   "ID: " & sID$ & vbCrLf & _
                   "Filename: " & sFileName$)

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