Jump to content

_stringbetween / counting array elements


BAM5
 Share

Recommended Posts

omg i need help this problem is becoming really annoying i cant figure it out

What i am trying to do is get the source get string betweens, i have no problem with that, but i have them type it in a for to next loop and some times that array element doesn't exist here is the part i have trouble with

$6 = _StringBetween ($html, '<H3 class=result>6 Letter Words</H3>', '<H3 class=result>5 Letter Words</H3>')
$6word = _StringBetween ($6[0], "<P class=result>", "</P>")

For $i = 0 To 8
    Send ($6word[$i] & "{enter}{space}")
    Sleep (700)
Next

the for to next loop tries to type a non existing array element and i get an error i need to find a way to count the number of elements and return the last existing element so i can enter a if then in there and get it to work

wish stringbetween would work like stringsplit and return $array[0] which ='s the amount of strings made

[center]JSON Encoding UDF[/center]

Link to comment
Share on other sites

  • Moderators

You need to either use the "Non" regexp option, or learn about escape characters.

Also, in the example you've provided, we have no <P class=result> a workable example is advised if you want "quick" and precise help in the future.

Try this:

$6 = _StringBetween ($html, '\<H3 class=result>6 Letter Words\<\/H3>', '\<H3 class=result>5 Letter Words\<\/H3>')
If IsArray($6) Then
    $6word = _StringBetween ($6[0], "\<P class=result>", "\<\/P>")
    If IsArray($6word) Then
        For $i = 0 To UBound($6Word) - 1
            Send ($6word[$i] & "{enter}{space}")
            Sleep (700)
        Next
    Else
        MsgBox(16, "Error", "Your code is failing at $6word")
    EndIf
Else
    MsgBox(16, "Error", "Your code is failing at $6 Array")
EndIf
This was typed in the quick response tab, so make sure I haven't typed any errors in quotes or variable names.

Edit:

The way that StringSplit returns it's element max stored in element [0] has been said to be a mistake.

If you ever want to find the max of an array, look up UBound()

UBound($myArray) - 1 will return the max elements you can search.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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