Jump to content
Sign in to follow this  
ParoXsitiC

\# with StringRegExp

Recommended Posts

I am trying to update a UDF to work with the current version of AutoIT. It is a multithread UDF located here: http://www.autoitscript.com/forum/index.ph...outine&st=0

It is mostly not working because of the many changes to StringRegExp in the past year or so. One of the biggest difficulties I am coming to is the use of \#. Is there anyway to emulate this in the newer StringRegExp?

For those who are not familiar with what \# use to do, here is a line from the old help file:

\# Position. Record the current character location in the test string into the returned content array.

Here are some examples of the UDF using it:

$sReturnStr = StdoutRead($iPID)
        $iNumChrsToRead = StringRegExp($sReturnStr, "(\d*?)(\#)(?:\$\[)", 1)
        $sReturnStr = StringTrimLeft($sReturnStr, $iNumChrsToRead[1])
        While StringLen($sReturnStr) < $iNumChrsToRead[0]
            $sReturnStr &= StdoutRead($iPID)
        WEnd

I attempted to fix it with this code, but it doesnt always work for everything:

$sReturnStr = StdoutRead($iPID)
        $iNumChrs = StringRegExp($sReturnStr, "(\d*?)(?:\$\[)", 1)
        $iNumChrsToRead = StringLen($iNumChrs[0])
        $sReturnStr = StringTrimLeft($sReturnStr, $iNumChrsToRead)
        While StringLen($sReturnStr) < $iNumChrs[0]
            $sReturnStr &= StdoutRead($iPID)
        WEnd

Share this post


Link to post
Share on other sites

The new current release version is 3.2.8.1 as of day-before-yesterday, and the fixes list some RegExp stuff specifically. I think you need to test against that version before going too far with your troubleshooting.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

This is an update for anyone else having the same problem I did. Here is the solution:

$iNumChrsToRead = StringRegExp($sReturnStr, "(\d*?)(\#)(?:\$\[)", 1)
        $sReturnStr = StringTrimLeft($sReturnStr, $iNumChrsToRead[1])

You first take note of whats to the left of the (\#), you will be using that later on. Now get rid of the (\#) so you're left with:

$iNumChrsToRead = StringRegExp($sReturnStr, "(\d*?)(?:\$\[)", 1)
        $sReturnStr = StringTrimLeft($sReturnStr, $iNumChrsToRead[1])

Now wherever you see $iNumChrsToRead[1] replace that with this:

StringInStr($sReturnStr, StringBeforeThe\#) + StringLen ( StringBeforeThe\#) - 1

Since our StringBeforeThe\# was (\d*?). We know that $iNumChrsToRead[0] will output the match. Therefore the whole thing turns into:

$iNumChrsToRead = StringRegExp($sReturnStr, "(\d*?)(?:\$\[)", 1)
        $sReturnStr = StringTrimLeft($sReturnStr, StringInStr($iNumChrsToRead[0]) + StringLen ($iNumChrsToRead[0]) - 1)

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...