InStr() function missing parameters
Closed this issue · 7 comments
Description
When using InStr() function as the AHK documentation suggests, the AHK++ extension seems to have missed a parameter that is important to my code which is the occurrence parameter.
AHK Docs: InStr(Haystack, Needle , CaseSensitive := false, StartingPos := 1, Occurrence := 1)
AHK++ : InStr(Haystack, Needle [, CaseSensitive?, StartingPos])
Reproduction steps
Steps to reproduce the behavior:
Use AHK++ and try to set an occurrence parameter. Example code given below:
File = "C:\Test\Test\Test.txt"
var := StrSplit(File, "backslash")
MsgBox % var.count()
pos := InStr(File, "backslash",False, 1, var.count())
MsgBox % pos
Expected behavior
It should provide the character position in a string based on the var.count() result, which would be the last "" within the string's name.
Additional context
InStr(Haystack, Needle [, CaseSensitive?, StartingPos])
requires a maximum of 4 parameters, and you are providing 5.
Try, pos := InStr(File, "", , var.count())
.
Maybe I didn't make it clear enough. The basic InStr function from AHK uses 5 parameters. I need that 5th parameter for occurrence. StrSplit only provides me a way to get the count of the last backslash in a file path, not the position of that backslash within the string. So it tells me there are X amount of backslashes which I want to use var.count() because it gives me the last occurrence. Then I use pos := InStr(File, "backslash", False, 1, var.count()) to get the position of that last backslash.
My primary issue is that Ahk++ doesn't have the 5th parameter that AHK has by default. Does that make more sense?
You have your start position
and occurrence
parameters in the wrong positions.
pos := InStr(File, "",,var.count(), 1)
See example #3.
And yes, the autocomplete is missing the 5th parameter.
InStr(Haystack, Needle , CaseSensitive := false, StartingPos := 1, Occurrence := 1) ????
The filepath can be 100 characters long, if I run a StrSplit(File, "backslash") its only going to return 4 or 5 even though the last backslash is going to be maybe character number 70 in the string. Please run my example code, it will maybe give you clarity to what Im asking for.
Regardless though, I can make this work in AHK Studio or Scite, its simply that Ahk++ doesn't pass through the occurence parameter all together.
You have your start position
and occurrence
parameters in the wrong positions.
File = "C:\Test\Test\Test.txt"
var := StrSplit(File, "\")
MsgBox % var.count()
pos := InStr(File, "\",False, var.count(), 1)
MsgBox % pos
Scrap that.
Try, pos := InStr(File, "\",,1, var.count()-1)
var.count()
gives you the number of strings that File
is split into, not the number of backslashes.
Ahh... that was it the -1, well darn. I do believe the tab complete parameters in InStr() should be updated to include occurrence as of right now it only shows:
InStr(Haystack, Needle [, CaseSensitive?, StartingPos])
Which is not all of the parameters. Was a simple oversight on my end, oh well ty!