Jump to content

String Parse Question.


Recommended Posts

I've searched the forum, googled and read the help docs, I think I know what functions to use, the string management functions. However I am not grasping at the logic of how to parse the string I want to parse. Here is the scenario: I have a webapp that outputs the following text when MouseClickDrag(ed), copied into clipboard, and set to a variable with $string = ClipGet ().

Cash: $105B     Cash flow: $27.03M  



Health

24

1:40 for more



Energy

57

1:27 for more



Stamina

4

That is exactly how it is formatted in notepad.exe.

The numbers may be larger or smaller ( more or less digits ) depending on a players level.

I would like to extract; "$cash = Cash: $105B, $cashFlow = Cash flow: $27.03M, $health = 24, $energy = 57, $stamina = 4".

and if easy enough I would like to parse out the time information.

I'm not asking for a complete script writeup, I would like enough help (hands on / visual) style to assist me in learning the logic of what I'm trying to accomplish in order to be able to use the logic in other areas of my program.

Thank You very much for your time in reading / replying to this.

And for those wondering, yes this is for Mobsters, a friend bet me I couldn't make a script for it, I want to prove him wrong LOL :) What have I gotten myself into? :)

Link to comment
Share on other sites

Hi, you might want to try something like this (I'm new to this too)

I pasted your text in text.txt

#Include <string.au3>
#Include <array.au3>

$file = FileOpen("C:\text.txt", 0)
$readtext = FileRead($file)
$array = _StringBetween($readtext, "Cash:", "Cash flow")
$Cash = _ArrayToString($array, @CRLF)
$array = _StringBetween($readtext, "Cash flow:", @CRLF)
$CashFlow = _ArrayToString($array, @CRLF)
$array = _StringBetween($readtext, "Health" & @CRLF & @CRLF, @CRLF)
$Health = _ArrayToString($array, @CRLF)
$array = _StringBetween($readtext, "Energy" & @CRLF & @CRLF, @CRLF)
$Energy = _ArrayToString($array, @CRLF)
$array = _StringBetween($readtext, "Stamina" & @CRLF & @CRLF, @CRLF)
$Stamina = _ArrayToString($array, @CRLF)
ConsoleWrite("$Cash = " & $Cash & @CRLF)
ConsoleWrite("$CashFlow = " & $CashFlow & @CRLF)
ConsoleWrite("$Health = " & $Health & @CRLF)
ConsoleWrite("$Energy = " & $Energy & @CRLF)
ConsoleWrite("$Stamina = " & $Stamina & @CRLF)
Link to comment
Share on other sites

Hmm... Is there not a edit button somewhere to edit posts?

Anyway...

I've been reading and I'm wondering if my logic should be as follows:

I should define "keywords", for example

Cash:
Health
Energy
and then place X amount of characters in a
$variable
following the end of my keyword, then strip out the white space. I'm just wondering if I'm going to run into problems in the future if say someone is at a low level and they don't have 6 or 8 digits worth of money.

Anyone know how I got about collecting characters in my string until I hit whitespace? That way I believe the function would work in any case. Any thoughts?

Link to comment
Share on other sites

OK, I just wanted to say Thank You very much! :) I didn't even know there was a UDF section of code lol. That is defiantly a great resource. I have almost perfected my code to make the functions work correctly. I will post the code when it is complete, for those that may learn from it. Sorry for the million posts. If someone could show me an edit button, I'd be grateful to use it.

Link to comment
Share on other sites

OK, so I got a little excited and a little ahead of myself.

Here is my function block.

Func advancedstats()
    MouseClick ( "", 172, 200 ) ; Click on the "Main" tab in the browser.
    Sleep ( 2000 ) ; Wait for the browser to load the "Main" page.
    MouseClickDrag ( "", 140, 156, 796, 160, 100 )
    Send ( "^c" ) ; Gather advanced stats.
    $advancedstats = ClipGet ( )
    
    $stringinput = _StringBetween( $advancedstats, "Cash:", "Cash flow:" )
    Global $cash = StringStripWS ( $stringinput, 1 )
    Sleep ( 100 )
    $stringinput = _StringBetween( $advancedstats, "Cash flow: ", "Health" )
    Global $cashFlow = StringStripWS ( $stringinput, 1 )
    Sleep ( 100 )
    $stringinput = _StringBetween( $advancedstats, "Health", "Energy" )
    Global $health = StringStripWS ( $stringinput, 1 )
    Sleep ( 100 )
    $stringinput = _StringBetween( $advancedstats, "Energy", "Stamina" )
    Global $energy = StringStripWS ( $stringinput, 1 )
    Sleep ( 100 )
    $stringinput = _StringBetween( $advancedstats, "Stamina" & @CRLF & @CRLF, @CRLF )
    Global $stamina = StringStripWS ( $stringinput, 1 )
    Sleep ( 100 )
    
    Run ( "notepad.exe" )
    WinWaitActive ( "Untitled - Notepad", "" )
    Send ( $cash, 1 )
    Send ( "{SPACE}" )  
    Send ( $cashFlow, 1 )
    Send ( "{SPACE}" )
    Send ( $health, 1 )
    Send ( "{SPACE}" )
    Send ( $energy, 1 )
    Send ( "{SPACE}" )
    Send ( $stamina, 1 )
Exit

$advancedstats is equal to the follwing in the clipboard.

Cash: $105B     Cash flow: $27.03M  



Health

24

1:40 for more



Energy

57

1:27 for more



Stamina

4

However when debugging "4 spaces followed by 0" ( not the actual text, but it wouldn't show " 0" in code blocks) is showing in notepad.exe

Can someone please help me clear things up. PLEASE :)

Link to comment
Share on other sites

I'm done now. For anyone that may care, I got my code worked out, her is the result. (All of this just to place the info into a GUI LOL!)

Func advancedstats()
    MouseClick ( "", 172, 200 ) ; Click on the "Main" tab in the browser.
    Sleep ( 2000 ) ; Wait for the browser to load the "Main" page.
    MouseClickDrag ( "", 140, 156, 796, 160, 100 )
    Send ( "^c" ) ; Gather advanced stats.
    $advancedStats = ClipGet ( )
    
    $array = _StringBetween( $advancedStats, "Cash: ", "Cash flow:" )
    $cash1 = _ArrayToString( $array, "" )
    $cash = StringStripWS ( $cash1, 8 )
    
    $array = _StringBetween( $advancedStats, "Cash flow:", "Health" )
    $cashFlow1 = _ArrayToString( $array, "" )
    $cashFlow = StringStripWS ( $cashFlow1, 8 )
    
    $array = _StringBetween( $advancedStats, "Health", "Energy" )
    $health1 = _ArrayToString( $array, "" )
    $health2 = StringTrimRight ( $health1, 18 )
    $health = StringStripWS ( $health2, 8 )
    
    $array = _StringBetween( $advancedStats, "Energy", "Stamina" )
    $energy1 = _ArrayToString( $array, "" )
    $energy2 = StringTrimRight ( $energy1, 18 )
    $energy = StringStripWS ( $energy2, 8 )
    
    $stamina1 = StringTrimLeft ( $advancedStats, 97 )
    $stamina2 = StringRegExp ( $stamina1, "(\d)" , 3 )
    $stamina3 = _ArrayToString ( $Stamina2, "" )
    $stamina = StringStripWS ( $stamina3, 8 )
    
    _ClipBoard_Empty()

    Run ( "notepad.exe" )
    WinWaitActive ( "Untitled - Notepad", "" )
    Send ( $cash, 1 )
    Send ( "{SPACE}" )  
    Send ( $cashFlow, 1 )
    Send ( "{SPACE}" )
    Send ( $health, 1 )
    Send ( "{SPACE}" )
    Send ( $energy, 1 )
    Send ( "{SPACE}" )
    Send ( $stamina, 1 )
Exit
EndFunc
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...