Jump to content

Need help to understand a function please.


Recommended Posts

ok im reading from a file on line 16

And using StringRegExpReplace will not work for this since the line get coded added to it for alpha change in it.

Here is the line when it has alpha in it.

<DIV style="FILTER: alpha(opacity=100); COLOR: #ffffff; ZOOM: 1" jQuery1231182309468="24">Health: 57/100</DIV>

Normally it is like this when there is no increase or decrease in Health point.

<DIV>Health: 57/100</DIV>

StringRegExpReplace works fine for it until i get the extra code.

So can StringExpReg be used instead?

Im not understanding how this function works, can anyone help me with an example using this line.

<DIV style="FILTER: alpha(opacity=100); COLOR: #ffffff; ZOOM: 1" jQuery1231182309468="24">Health: 57/100</DIV>

All i want to read is 57/100 from the line. My code that works until the alpha code is added at runtime when health is increased or decreased. The opacity = 100 is constantly changed in decimal down to 100 to make the color change, so parsing this will parse out the health value.

$Health = StringRegExpReplace($Health_line, "[<DIV>Health: <DIV>]", "")

$Health_var = StringSplit($Health, "/", 0)

MsgBox(0, "Current Health", $Health_var)

Using StringTrim and Left/Right will not work for this because 57/100 can be anything larger depending on level. Example: Current health 5000/10000 and max health. But there is no top out on these, they get larger the higher level you get.

So StringRegExp looks like what i need to use, but am confused on how it works.

Can someone please explain this function for me.

Edited by £åߥ®Ñth
Link to comment
Share on other sites

ok im reading from a file on line 16

And using StringRegExpReplace will not work for this since the line get coded added to it for alpha change in it.

Here is the line when it has alpha in it.

<DIV style="FILTER: alpha(opacity=100); COLOR: #ffffff; ZOOM: 1" jQuery1231182309468="24">Health: 57/100</DIV>

Normally it is like this when there is no increase or decrease in Health point.

<DIV>Health: 57/100</DIV>

StringRegExpReplace works fine for it until i get the extra code.

So can StringExpReg be used instead?

Im not understanding how this function works, can anyone help me with an example using this line.

<DIV style="FILTER: alpha(opacity=100); COLOR: #ffffff; ZOOM: 1" jQuery1231182309468="24">Health: 57/100</DIV>

All i want to read is 57/100 from the line. My code that works until the alpha code is added at runtime when health is increased or decreased.

$Health = StringRegExpReplace($Health_line, "[<DIV>Health: <DIV>]", "")

$Health_var = StringSplit($Health, "/", 0)

MsgBox(0, "Current Health", $Health_var)

Using StringTrim and Left/Right will not work for this because 57/100 can be anything larger depending on level. Example: Current health 5000/10000 and max health. But there is no top out on these, they get larger the higher level you get.

So StringRegExp looks like what i need to use, but am confused on how it works.

Can someone please explain this function for me.

Explaining StringRegExp is otoo complicated IMO for a simple answer here, not that I could give a competent answer anyway. You need to study the help and the links given in the help and look at examples and spend some time on it.

If you only need the information between "Health:" and "</DIV>" then _StringBetween looks like what you need. It's simple to use as well.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Explaining StringRegExp is otoo complicated IMO for a simple answer here, not that I could give a competent answer anyway. You need to study the help and the links given in the help and look at examples and spend some time on it.

If you only need the information between "Health:" and "</DIV>" then _StringBetween looks like what you need. It's simple to use as well.

Hmmm, String between. Let me look at this function.

Thank you for the reply as well, i do realize it StringRegExp is complicated. I dont have allot of posts becasue most of my questions are answered by the help file. :)

I cant seem to grasp what/ how to implement StringExpReg. Or if it is even what i need.

Link to comment
Share on other sites

#include <string.au3>
$s='<DIV style="FILTER: alpha(opacity=100); COLOR: #ffffff; ZOOM: 1" jQuery1231182309468="24">Health: 57/100</DIV>'
$as=_StringBetween($s,"Health: ","</DIV>")
MsgBox(0,$s,$as[0] )
Thanks for your interest in this TinyBoy. I did this very thing and my return is blank ???

While 1

$stats = @TempDir & "\stats.txt"

$file = FileOpen($stats , 0)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

Else

$Health_line = FileReadLine($file, 16)

If @error = -1 Then Exit

$Health = _StringBetween($Health_line,"Health: ","</DIV>")

MsgBox(0, "Health", $Health )

FileClose($file)

EndIf

WEnd

***

Fixed, my problem was MsgBox(0, "Health", $Health )

Corrected: MsgBox(0, "Health", $Health[0] )

Edited by £åߥ®Ñth
Link to comment
Share on other sites

Try:

MsgBox(0, "Health", $Health[0] )

_StringBetween returns an Array.

Thanks for your interest in this TinyBoy. I did this very thing and my return is blank ???

While 1

$stats = @TempDir & "\stats.txt"

$file = FileOpen($stats , 0)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

Else

$Health_line = FileReadLine($file, 16)

If @error = -1 Then Exit

$Health = _StringBetween($Health_line,"Health: ","</DIV>")

MsgBox(0, "Health", $Health )

FileClose($file)

EndIf

WEnd

Link to comment
Share on other sites

Here's one way to solve this problem, using StringRegExp .

; Wrapped your line into a variable

$line = '<DIV style="FILTER: alpha(opacity=100); COLOR: #ffffff; ZOOM: 1" jQuery1231182309468="24">Health: 57/100</DIV>'

; Hold the result of the regular expression in a variable

$result = StringRegExp( $line, "\d{1,3}/\d{3}",1 ) ; 1 = find an array of matches

; Console Write the result of the regular expression

ConsoleWrite($result[0] & @CRLF) ; [0] = the first index of the array

...Of course, using index 0 to contain data and not a count of the length of the array goes against AutoIt standards, but for this example it works

--------------------------------------------------------------------------------------

The main thing to consider here is what regular expression you would like to use. I have used the following:

"\d{1,3}/\d{3}"

I am looking for a digit ( \d ) in length of 1 to 3 ( {1,3} ) followed by a slash ( / ) then exactly three digits ( \d{3} ).

Another regular expression that would do the same thing is: (\d|\d\d|\d\d\d)/\d\d\d

Effectively, any expression that looks for 1 - 3 numbers followed by a slash, then exactly 3 more numbers will get you what you are looking for.

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...