|
-
Apr 14th, 2007, 01:22 PM
#1
Thread Starter
Hyperactive Member
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
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!!!!! 
-
Apr 14th, 2007, 01:41 PM
#2
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.
-
Apr 14th, 2007, 01:45 PM
#3
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.
-
Apr 14th, 2007, 01:58 PM
#4
Thread Starter
Hyperactive Member
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
but when it is on normal it looks like this
I need to remove those
Visual Basic Rules!!!!! 
-
Apr 14th, 2007, 02:08 PM
#5
Re: Hard Question Need help... (Parsing)
You can use RTrim() or Trim() to get rid of the trailing space. The || is probably vbCrLf and you could use Replace() to replace it with spaces.
-
Apr 14th, 2007, 02:15 PM
#6
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
-
Apr 14th, 2007, 08:02 PM
#7
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).
-
Apr 14th, 2007, 09:50 PM
#8
Re: Hard Question Need help... (Parsing)
 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. :/
-
Apr 14th, 2007, 11:43 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|