Hi
magicinmath,
magicinmath wrote:can it be possible to use a parameter for the delimiter in StrSplit
If you mean pass a function parameter instead of use an hard-coded string as delimiter:yes;
StrSplit delimiter's parameter admits variables. You simply have to add a delimiter parameter in the definition of your function and specify it as param in the
StrSplit function inside the body of your function.
StrSplit delimiter's parameter also accept arrays so you even can specify more than one delimiter to be taken in consideration when the function will execute. However, in this case, you should make this parameter
variadic:
Code: Select all
MyFunc(string, array*) {
Loop % (arr:=StrSplit(string, array)).length()
MsgBox % arr[a_index]
}
MyFunc("A@B#C$D", ["@", "#", "$"]*) ; the asterisk after the final parameter marks the function as variadic
Concerning the strucure of the loop maybe, and instead of calling many times
StrSplit- especially if you plan to deal with huge arrays - you could first 'stringify' your array, call
StrSplit just one time and return an array wich retains only the element at index 2, 5, 8, 11, 14 --> 3n-1- magic in math!
Code: Select all
data:=["somedata@A@birthday", "moredata@B@birthday", "moredata@C@birthday", "moredata@D@birthday", "moredata@E@birthday"]
makearray(__arrIn, ByRef __arrOut, __delimiter:="@") {
__str := "", __arrOut := []
Loop % __arrIn.length()
__str .= __arrIn[a_index] . "@"
Loop % ((__arr:=StrSplit(__str, __delimiter)).length()/3)
__arrOut.push(__arr[(3*a_index)-1]) ; https://answers.yahoo.com/question/index?qid=20080819031639AAVzhO1
}
makearray(data, outputArray, "@")
Loop % outputArray.length()
MsgBox % outputArray[a_index]
Hope this helps.