Jump to content

StringRegExp


Recommended Posts

This is a whole page, spaces removed.

Themoreattackturnsyouuseinanattack,themoreexperienceandgoldyouwillget.Gold:991,954UntrainedCitizens:19Level:19Experience:177,669(nextlevelin9,831)TurnsAvailable:371UsernameorIDTimeUntilNextTurn9:56DarkThroneTime15:168/15-
OmegaLaunch/StatusUpdateUntrainedCitizens:19GoldAvailable:991,954TypeYou
HaveCostQuantityMiner2,3742,000Soldie

I need to get the Gold ammount out of this text

i got this code, and it does that :

$klad=Clipget()

$klad=StringStripWS ($klad, 8)

MsgBox(0, "Dark", $klad )

$start = StringInStr($klad,"Gold:") + 5
$end = StringInStr($klad,"Untrained")
$result = StringMid($klad, $start , $end - $start)

MsgBox(0,"Result",$result)

But i would like to put them in a array with StringregExp

#include <array.au3>

Dim $lost [20]

$klad=Clipget()

$lost=StringRegExp ($klad, "Gold:(\d)", 3)

MsgBox(0, "Window", $lost[1] );this displays nothing

I just cant seem to bend my mind around regular expressions, feel so stupid :whistle:

It seems to me that stringparsing becomes much easier with StringRegExp, if i could just figure out how to express stuff. :dance:

Who can help me out ?

Edited by WhiteCrow
Link to comment
Share on other sites

Does this work for you.

$x = "Themoreattackturnsyouuseinanattack,themoreexperienceandgoldyouwillget.Gold:991,954UntrainedCitizens:19Level:19Experience:177,669(nextlevelin9,831)TurnsAvailable:371UsernameorIDTimeUntilNextTurn9:56DarkThroneTime15:168/15-OmegaLaunch/StatusUpdateUntrainedCitizens:19GoldAvailable:991,954TypeYouHaveCostQuantityMiner2,3742,000Soldier(Offense)01,500Guard(Defense)01,500Spy402,500Sentry(AntiSpy)02,500Advancedunitscannotbeuntrained.AlladvancedunitsmustbetrainedfromBasicunitsinthatsameclass(soldierstoknights,sentriestosentinels...).VeteranSpiescannotbesentonspymissions.TypeYouHaveCostQuantityKnight(Offense)15610,000Archer(Defense)13910,000VeteranSpy5610,000Sentinel(AntiSpy)9710,000Copyright2004-2005LazarusSoftware[AntiSpamPolicy|PrivacyPolicy|TermsofUse|Rules]"
$pattern = "(Gold:.*?Untrained)"
$msg = ""
$y = StringRegExp($x,$pattern,3)
$error = @error
If @error = 0 and @extended = 1 Then
    For $z = 0 to UBound($y) - 1
        $msg = $msg & $y[$z] & @CRLF
    Next
    Msgbox(0,"",$msg)
Else
    msgbox(0,"error","@error = "    &  $error & @CRLF & "@extended = " & @extended)
EndIf
[
Link to comment
Share on other sites

Your code works just fine :whistle:

This is what i made of it

$x = "Themoreattackturnsyouuseinanattack,themoreexperienceandgoldyouwillget.Gold:991,954UntrainedCitizens:19Leve

$pattern = "(Gold:.*?Untrained)"

$msg = ""
$y = StringRegExp($x,$pattern,1)

$error = @error
If @error = 0 and @extended = 1 Then
    For $z = 0 to UBound($y) - 1
        $msg = $msg & $y[$z] & @CRLF
    Next
    Msgbox(0,"",$msg)
Else
    msgbox(0,"error","@error = "    &  $error & @CRLF & "@extended = " & @extended)
EndIf

$msg=StringTrimRight($msg, 11)
$msg=StringTrimLeft($msg, 5)
$msg=StringReplace ($msg, ",", "")

$gold=Number($msg)

Msgbox(0,"gold",$gold)

Thank you verry much Steve8tch, now i have the gold in integer, i can calculate some stuff with it :dance:

Just what i need...

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...