Results 1 to 9 of 9

Thread: Hard Question Need help... (Parsing)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    Hard Question Need help... (Parsing)

    Ok basicly here is what I need to do... I have a string that is being generated by a server... it looks like this...

    [14:19:05] Connecting to rstalk.no-ip.org:8767
    [14:19:05] Connected to server ..::Runescape Talk::..
    [14:19:05] Welcome To Runescape Talk, [http://www.runescape.com/]!
    [14:19:05] *priv* : ~~~ [ WELCOME ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    [14:19:05] *priv* : Hello Chris <SSA - 85/99 Fletch>! Welcome to the ..::Runescape Talk::...
    [14:19:05] *priv* :
    [14:19:05] *priv* : Please note that your IP address 24.31.114.189 has been logged.
    [14:19:05] *priv* : Your current Ping delay is about 45 ms.
    [14:19:05] *priv* : The server detected that 0% of your UDP packets get lost.
    [14:19:05] *priv* : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [ WELCOME ] ~~~
    [14:19:11] Guest1 quit
    [14:19:18] *priv* skill.bot: Hey
    [14:19:25] *priv* SERVER: Client "Jake" got kicked from Server by "superadmin", reason "no recording"
    [14:19:25] Jake was kicked from the server by player (no recording)
    [14:19:31] Jake joined channel
    [14:19:31] *priv* SERVER: Client "Jake" got kicked from Server by "superadmin", reason "no recording"
    [14:19:31] Jake was kicked from the server by player (no recording)
    it is showing the status of my TeamSpeak Server... you dont need to know anything about TS to answer my question


    about half way down in the example is this
    *priv* skill.bot: Hey

    I need my textbox to display the most recent *priv* skill.bot: and nothing else...

    so some parsing is going to be required I just cant figure it out


    this string is always updating... so it may include more than one ( *priv* skill.bot adfdf ) string....

    I just need the textbox to return the instance that is the farthest away from the beginning of the string... aka the newest one
    Visual Basic Rules!!!!!

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Hard Question Need help... (Parsing)

    I'm heading out so I can't give you a fleshed out and debugged solution, but it's fairly straightforward:
    Code:
    Public Function LastSkillBotMessage(pstrMessages As String) As String
        Const FindString = "*priv* skill.bot:"
        Dim strMsg() As String
        Dim lngPos As Long
        Dim i As Long
    
        strMsg = Split(pstrMessages, vbNewLine)
        For i = 0 to Ubound(strMsg)
            lngPos = InStr(strMsg(i), FindString) 
            If lngPos <> 0 Then
                lngPos = lngPos + Len(FindString)
                LastSkillBotMessage = Mid$(strMsg(i), lngPos, Len(strMsg(i) - lngPos - 2)
                Exit Function
            End If
        Next
    End Function
    You may need to tweak this, but the basic idea is there.

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Hard Question Need help... (Parsing)

    Code:
        Dim lngPos As Long, lngLastPos As Long
        lngLastPos = InStr(strBuffer, "*priv* skill.bot:")
        Do Until lngLastPos < 1
            lngPos = lngLastPos
            lngLastPos = InStr(lngLastPos + 1, strBuffer, "*priv* skill.bot:")
        Loop
        If lngPos > 0 Then
            lngLastPos = InStr(lngPos, strBuffer, vbNewLine)
            If lngLastPos < 1 Then lngLastPos = Len(strBuffer)
            MsgBox Mid$(strBuffer, lngPos, lngLastPos - lngPos)
        Else
            MsgBox "No message from skill.bot"
        End If
    That should get you started.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    Re: Hard Question Need help... (Parsing)

    Ok thanks... now I need to remove spaces in the output...

    so like I get "username ", I need it to be "username"

    I tryed replace() but that didint work...



    when I have the textbox on multiline it looks like this

    username
    but when it is on normal it looks like this

    username||
    I need to remove those
    Visual Basic Rules!!!!!

  5. #5

  6. #6
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Hard Question Need help... (Parsing)

    If I understand correctly, wouldn't the quickest way be to use the InstrRev() function since you're searching from the end of the text (last message from *priv* bot)?

    Like this (didn't test it):
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        'Use it like:
        Dim strBot As String
        
        strBot = LastBotSpeak(Text1.Text)
    End Sub
    
    Private Function LastBotSpeak(ByRef Text As String) As String
        Dim lonStart As Long, lonSLen As Long
        Dim lonEnd As Long
        
        lonStart = InStrRev(Text, "*priv* skill.bot:")
        lonSLen = 17 'Length of *priv* skill.bot:
        
        If lonStart > 0 Then
            lonStart = lonStart + lonSLen
            lonEnd = InStr(lonStart, Text, vbCrLf)
            
            If lonEnd > 0 Then
                LastBotSpeak = Mid$(Text, lonStart, lonEnd - lonStart)
            End If
        End If
        
    End Function

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Hard Question Need help... (Parsing)

    DigiRev: it would if InStrRev wasn't coded badly. It is slow, and that is because it reverses the strings before searching (instead of just handling data in different direction, which would be faster in an order of magnitude). So most often InStr wins in speed even when what is to be found is at the end of the buffer. Plus the length of code isn't really that big (as you can see from my code example in comparison to what you posted).

  8. #8
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Hard Question Need help... (Parsing)

    Quote Originally Posted by Merri
    DigiRev: it would if InStrRev wasn't coded badly. It is slow, and that is because it reverses the strings before searching (instead of just handling data in different direction, which would be faster in an order of magnitude).
    Oh man wish I had known that.

    Also I could have condensed my code to something a lot shorter, but it's one of my OCDs...

    I have a way of formatting code that takes up a lot of space but it looks neat and clean to me. I spend half my time programming actually making code look neater. :/

  9. #9
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Hard Question Need help... (Parsing)

    Readable code is more important than compact code

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