Jump to content

StringInStr - position parameter broken?

Recommended Posts

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



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
Link to post
Share on other sites

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
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...