AutoHotKey - switch statement with a series of InStr functions
I have created an AutoHotKey script with a bunch of if
functions that rely on InStr, similarly as in the example below, and it already does what I want. Is it possible, though, to convert it to a Switch
statement to simplify it and avoid repeating if InStr...
several times?
The value of fullPath
remains the same during the execution of the script.
fullPath = "%1%"
;input examples: "c:\example\lalala lynx lalala.txt" and "c:\another folder\test\kiwi testtest.txt"
if InStr(fullPath, "kiwi")
{
Goto, FRUIT
}
if InStr(fullPath, "Estonia")
{
Goto, COUNTRY
}
if InStr(fullPath, "lynx")
{
Goto, ANIMAL
}
Try to use an associative array:
assocArray := { "kiwi" : "FRUIT" , "Estonia" : "COUNTRY" , "lynx" : "ANIMAL" }
for key, val in assocArray
{
if InStr(fullPath, key)
Goto, %val%
}