Jump to content

Recommended Posts

Posted

what i am trying to do is to get info from the strings

but i ran into some problems

1) i am not sure how to use the "|" function in StringRegExp to get both "hit" and "slash"

2) The name on the 3rd line changes from "You" to "A Tall Dragon", not sure how to have it search for both names

Global $i = 1, $name, $dmg

While 1
    $read = FileReadLine(@scriptdir&"\test.txt", $i)
    If @error = -1 Then ExitLoop
    $dmg= StringRegExp($read, "for (\d+)", 1)
    $name = StringRegExp($read, "(\b\w+\b) hit", 1)
    If $dmg = 0 Then
    Else
    $dmg1 = $dmg[0]
    $name1 = $name[0]
    MsgBox("", "Info", $name1 &" = " & $dmg1)   
    EndIf
    $i = $i + 1
Wend

The txt file

You slash Dragon for 1183 damage.
You hit Dragon for 1217 damage.
A Tall Dragon hits you for 96 damage.
Posted

Dim $sStr = 'You slash Dragon for 1183 damage.' & @CRLF & _
            'You hit Dragon for 1217 damage.' & @CRLF & _
            'A Tall Dragon hits you for 96 damage.'

Dim $sPatt = '(.*?)(?:hit|slashe?)s?.*?for\s*(\d+)'
Dim $aLines = StringSplit($sStr, @CRLF, 1)

For $i = 1 To $aLines[0]
    Local $aMatch = StringRegExp($aLines[$i], $sPatt, 1)
    If UBound($aMatch) = 2 Then ConsoleWrite('Hit: ' & $aMatch[0] & @TAB & 'Dmg: ' & $aMatch[1] & @CRLF)
Next

Posted

hi one more question,

there happens to be a timestamp in front of each line [1:41:21 PM Jun 04 2009]

How come this doesn't work?

Dim $sPatt = '(]) (.*?)(?:hit|slashe?)s?.*?for\s*(\d+)'

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...