MightyMalcolm

StringInStr - position parameter broken?

3 posts in this topic

#1 ·  Posted (edited)

Hello everyone^^

I am somewhat new to AutoIt so please bear with me. I always thought that I was able to read, but neither helpfile nor internet search were able to explain the following behaviour to me:

ConsoleWrite(StringInStr("hey<a>ho!", "<a>")                                     & @CRLF)
ConsoleWrite(StringInStr("hey<a>ho!", "<a>", Default, Default, Default)          & @CRLF)
ConsoleWrite(StringInStr("hey<a>ho!", "<a>", Default, Default, Default, Default) & @CRLF)

The console output is

4
0
0

 

My aim was to use the position parameter and so I did. Took me quite a while to find out what part of my code was causing the unexpected results. For now, I am working around this problem with the construction given in the helpfile: StringInStr(StringMid($string, $start), $substring), but this obviously isn't now how it's meant to be.

Any help with this is greatly appreciated :)

Edited by MightyMalcolm

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The default values for StringInStr aren't the "Default"-Keyword. They are Integer-values. So your'e Input will be implicitly casted to int. And Because "Int(Default) = 0" your input implicitly becomes: 

StringInStr("hey<a>ho!", "<a>", 0, 0, 0, 0)

This leads to @error=1 because these are invalid values for "occurance" and "start".

Have a look at the help file for Default:

If used, the passed parameter will be set to the Default keyword and not to an optional parameter value, if defined.

So if you only want to set the "start"-parameter this is the right syntax:

StringInStr("hey<a>ho!", "<a>", 0, 1, $myStartValue)

 

Edited by AspirinJunkie

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Dang! I tried replacing the Default-keyword for integers, just like you said, but it seems I never actually replaced ALL of them at the same time %) So much for thorough testing. My bad there.

Cheers and thanks! :)

Edited by MightyMalcolm

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