Here is a simple function that get bracketed elements within another bracket.
For example, if the string is "[XXX[1]XXX[2]X[3]XXX]", the function will acquire [1], [2] and [3] and put them into an array.
You can specify a depth of level. Thus if you have a string like [XXX[1[third level1]]XXX[2]X[3[third level2]XXX]. The function can extract [thirdlevel1] and [thirdlevel2] if you specify level depth to 3.
A question: can I write a function which outputs objects (arrays)? I found it rather lame to use a separator symbol.
Thank you!
InputText := "[XXX[1]XXX[2]X[3]XXX]"
OutputArray :=object()
BracketParse(InputText,OutputString)
msgbox % OutputString
stringsplit , TempArray, OutputString,``
loop , %TempArray0%
{
msgbox % TempArray%a_index%
}
BracketParse(InputText, byref OutputString, SearchLevel=2)
{
LeftBrackets := "{[("
RightBrackets := ")]}"
ElementCounter := 0
Counter :=strlen(InputText)
loop, %Counter%
{
CurrentChar := SubStr(InputText, A_Index, 1)
If (InStr(LeftBrackets, CurrentChar))
CurrentLevel += 1
If (CurrentLevel >= SearchLevel)
CurrentElement .= CurrentChar
If (InStr(RightBrackets, CurrentChar))
{
CurrentLevel := CurrentLevel - 1
If (CurrentLevel = SearchLevel - 1)
{
OutputString .= CurrentElement . "``"
CurrentElement =
}
}
}
len := strlen(OutputString) -1
stringleft, OutputString, OutputString, %len%
}




