Results 1 to 5 of 5

Thread: parse this...

  1. #1

    Thread Starter
    Lively Member Scorpionz's Avatar
    Join Date
    Feb 1999
    Location
    lafayette/kaplan, louisiana, usa
    Posts
    72

    Exclamation

    how would i be able to parse a string like this:

    373 3 3 113 "hello there" "sup all" 4 4

    into this:

    373
    3
    3
    113
    hello there
    sup all
    4
    4

  2. #2
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Well if you have VB6 you can use the Split function with a " " as delimiter. If you have VB5, no such command.

    But, tada, I have a VB5 Split function for you!

    Code:
    Public Function WordSplit(sWords As String, sDelim As String) As Variant
    
    	Dim sTemp As String
    	Dim vWords() As Variant
    	Dim n, nCount As Integer
    
    	nCount = 0
    	sTemp = sWords
    
    	Do
    		n = InStr(1, sTemp, sDelim)
    		ReDim Preserve vWords(nCount)
    		If n = 0 Then
    			vWords(nCount) = sTemp
    		Else
    			vWords(nCount) = Left$(sTemp, n)
    			If Right(vWords(nCount), 1) = sDelim Then
    				vWords(nCount) = Mid(vWords(nCount), 1, Len(vWords(nCount)) - 1)
    			End If
    			sTemp = Mid$(sTemp, n + 1)
    		End If
    
    		nCount = nCount + 1
    
    	Loop Until n = 0
    
    	WordSplit = vWords
    
    End Function
    The code above was not written by me Alas, I do not know who the author was.
    Donald Sy - VB (ab)user

  3. #3
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    Try this:
    VB6 ONLY!!! (otherwise, maybe someone will post the split code for vb5)
    Code:
    Sub SplitIt(MyStr As String)
    Dim Splited
    
    Splited = Split(MyStr, " ")
    For i = LBound(Splited) To UBound(Splited)
        Debug.Print TrimQuotes(Splited(i))
    End If
    
    End Sub
    
    Function TrimQuotes(String1 As String) As String
    Dim FirstChr As String
    Dim LastChr As String
    FirstChr = Left(String1, 1)
    LastChr = Right(String1, 1)
    
    If FirstChr = Chr(34) And LastChr = Chr(34) Then
        TrimQuotes = Mid(String1, 2, Len(String1) - 1)
    Else
        TrimQutoes = String1
    End If
    End Sub
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  4. #4
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    I See someone did post the VB5 Split Function!!! Before Me!!!
    (I haven't tested my trim quotes function, but it should work)
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  5. #5

    Thread Starter
    Lively Member Scorpionz's Avatar
    Join Date
    Feb 1999
    Location
    lafayette/kaplan, louisiana, usa
    Posts
    72

    Exclamation

    naa, thats not gonna work...

    i need to parse out the first 4 strings then parse out the words in ""s, but at the same time keeping there spacing, and then parse out the last 2 strings so that it comes out as:

    373
    3
    3
    113
    hello there
    sup all
    4
    4

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