Object.HasValue/Contains/KeyOf/FindValue - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=30536
I have been working on my own functions for this.
I have been thinking of whether there should be an options parameter:
- case sensitive
- return first match/all matches/position of first match/positions of all matches/number of matches
- needles are: values/names of keys/a delimiter-separated string/values as delimiter-separated strings
- return delimiter-separated string/array of key names
- specify delimiter(s), possibly by Ord number(s)
- (an additional possible parameter:) check whether haystack contains none/all of needles (i.e. this can make the function give up earlier and hence run faster)
I see the overall template as:
does [A] match/contain/start/end
Where A or B can be:
- a variable / a comma-separated list (a string)
- an array's key names
- an array's values (key contents)
- content that is not a string (key contents)
Anyway, I'm thinking that I may take my 4 StrIn/StrContains/StrStarts/StrEnds functions, and boost them with object/array support, either for needles only (in which case separate Array functions), or to support strings *and* arrays/objects.
At the moment I have:
Code: Select all
;Note: It is difficult to choose between default: vDelim="," or vDelim="", I believe that vDelim="" (no delimiters) is a better assumption, because if commas are a delimiter by default this can cause surprises. I might propose JEE_StrContainsC, JEE_StrContainsP functions, where comma/pipe are default delimiters for convenience.
JEE_StrContains(ByRef vText, ByRef vNeedles, vDelim="", vCaseSen=0, ByRef vMatch="")
{
if (vDelim = "")
if InStr(vText, vNeedles, vCaseSen)
{
if IsByRef(vMatch)
vMatch := vNeedles
return 1
}
else
return 0
Loop, Parse, vNeedles, % vDelim
if InStr(vText, A_LoopField, vCaseSen)
{
if IsByRef(vMatch)
vMatch := A_LoopField
return A_Index
}
return 0
}
;==================================================
;early days here (I might have done more, but was undecided on how to specify key names v. value contents as the haystack, while keeping the parameters consistent with StrContains)
JEE_ArrayContains(oArray, vNeedle)
{
for vKey, vValue in oArray
{
if InStr(vValue, vNeedle)
return A_Index
}
return 0
}
topic split because it is totally off topic