Results 1 to 12 of 12

Thread: parsing

  1. #1

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

    Exclamation

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

    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

  2. #2
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    How is the Information stored ? In a file or a String ? I'm going to assume it's in a string . I'm also going to assume your using VB6 . Try something like this .

    Code:
    Dim ParsedData( )
    Dim Data as String 
    If Trim(Data) <> "" And InStr(1, Data, ":") Then
    ParsedData = Split(Data, " ", -1)
    You can Then Access the elements of the parsedData array like . This will return element 1 .
    Code:
    msgbox parsedData(0)
    Hope that helped a little . I just woke up .

    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  3. #3

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

    Exclamation

    using vb5, sorry...

  4. #4
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Scorpionz ,

    I Don't think the split function is in VB5 , I Don't know another way to do it .

    Sorry ,
    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Thumbs up

    Here's mysplit by Iain, it should work almost the same (you pass the array instead) as split except it's a lot faster for larger arrays
    Code:
    Private Sub Mysplit(Source, searchs As String, ByRef Arr() As String)
        Dim pos As Long, pos2 As Long, x As Long
        pos = 0
        If Right(Source, Len(searchs)) = searchs Then
            Source = Mid(Source, 1, Len(Source) - Len(searchs))
        End If
        Do
            pos = InStr(pos + 1, Source, searchs, vbTextCompare)
            If pos = 0 Then Exit Do
            ReDim Preserve Arr(x)
            Arr(x) = Mid(Source, pos + 1, pos + Len(searchs) - 2)
            x = x + 1
        Loop
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593
    Change all that to Right$ instead of Right and Mid$ instead of Mid -- and Left$ instead if Left, for that matter.

    Appending the $ suffix -- for some reason -- makes VB 5 apps perform better after compilation.

    And, hey keda .. no offense

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Well it's Iains, so it's np, but in Vb6, some of those just disappear
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    355
    the $ thing is odd; is it that right$ etc are especially for strings, whereas right, etc take a variant?
    buzzwords are the language of fools

  9. #9

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

    Exclamation grrrrrrrrrrrr

    ok, none of this is working out properly... =\

  10. #10
    Guest
    Just use this code from Megatron, rearrange it around and you get:

    Code:
    Private Function RemoveText(ByVal Text As String) As String
    'from Megatron
        Dim i As Integer
        Dim bInTag As Boolean
        Dim strTmpStr As String
    
        bInTag = False
        For i = 1 To Len(Text)
            If Not bInTag Then
                If Mid(Text, i, 1) <> """" Then
                    strTmpStr = strTmpStr & Mid(Text, i, 1)
                Else
                    bInTag = True
                End If
            Else
                If Mid(Text, i, 1) = """" Then
                    bInTag = False
                End If
            End If
        Next
    
        RemoveText = strTmpStr
    End Function
    
    
    Private Sub Command1_Click()
        
        Dim strString As String
        strString = "373 3 3 113 ""hello there"" ""sup all"" 4 4"
        MsgBox RemoveText(strString)
        
    End Sub

  11. #11

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

    Exclamation about to give up =\

    yes, that would work, but i would want the string to be added to a listbox as so:

    373
    3
    3
    113
    hello there
    sup all
    4
    4

  12. #12
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Yeah, so after that, use the split kedaman suggested.
    Donald Sy - VB (ab)user

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