Jump to content

Why doesn't it work the same? 3.1.1.0 -> 3.1.1.87


Recommended Posts

I have a function that will parse a string by giving it a "before" and "after" match, and put all the results in an array. It works fine for 3.1.1.0, but when running it in 3.1.1.87, it doesn't work right, and I don't have a clue as to why. I even rewrote the function to be completely different, and it still won't work.

Here's the old func

#include <Array.au3>
Func _ArrayParse($str, $before, $after)
    Dim $return[1]
    $on = 1
    While StringInStr($str, $before, 0, $on)
        $temp1 = StringSplit(StringMid($str, StringInStr($str, $before, 0, $on)), $before, 1)
        If $temp1[1] Then
            $temp2 = StringSplit($temp1[1], $after, 1)
        Else
            $temp2 = StringSplit($temp1[2], $after, 1)
        EndIf
        _ArrayAdd($return, $temp2[1])
        $on = ($on + 1)
    Wend
    _ArrayDisplay($return, "")
EndFunc

And here's what I rewrote it as

#include <Array.au3>
Func _ArrayParse($str, $before, $after)
    Dim $return[1]
    $temp1 = StringSplit($str, $before, 1)
    If StringLeft($str, StringLen($before)) == $before Then
        $start = 1
    Else
        $start = 2
    EndIf
    For $i = $start To Ubound($temp1) - 1 Step 1
        $temp2 = StringSplit($temp1[$i], $after, 1)
        _ArrayAdd($return, $temp2[1])
    Next
    _ArrayDisplay($return, "")
EndFunc

The best way to see what I'm talking about, is to use either of those 2 functions, and include the code below

$url = "http://www.google.com/search?hl=en&q=autoit"
$file = "html.txt"
InetGet($url, $file)
$html = FileRead($file, FileGetSize($file))
FileDelete($file)
_ArrayParse($html, "<a", ">")

I'm somewhat new to AutoIt, but this seems like it's something simple. If anyone could help, I would appreciate it. Thanks in advance.

Link to comment
Share on other sites

I don't know answer to your question (what changed)

but instead of your UDF _ArrayParse it's better to use function StringRegExp

$output = StringRegExp($html, '(?i)<a(.*?)>', 3); (?i) -> case insensitive
I don't have much experiance with that function, honestly it confuses the hell out of me, but I'll just change your example as needed. Thanks for the quick reply.

Also, I rewrote the function, yet again.

Func _ArrayParse($str, $before, $after)
    Dim $return[1]
    $on = 1
    While StringInStr($str, $before, 0, $on)
        $temp1 = StringMid($str, StringInStr($str, $before, 0, $on) + StringLen($before))
        $temp2 = StringMid($temp1, 1, StringInStr($temp1, $after, 0, 1) - StringLen($after))
        _ArrayAdd($return, $temp2)
        $on = ($on + 1)
    Wend
    _ArrayDisplay($return, "")
EndFunc

That seems to work in .87. It looks like my problem is with StringSplit. Even though I have my flag set use the whole string as a split, it's splitting each occurance of "<" and "a", instead of splitting "<a". Is this a bug on my part, or in .87 ?

Link to comment
Share on other sites

It looks like my problem is with StringSplit. Even though I have my flag set use the whole string as a split, it's splitting each occurance of "<" and "a", instead of splitting "<a". Is this a bug on my part, or in .87 ?

I filed a bug report for StringSplit and use the flag of 1 for .87. Same bug maybe affecting your UDF. It has been fixed in .88 and I recommend downloading it. Thankyou to the Devs for the fix. B)
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...