- Hello One - Hello Two_Hello Three (Hello Four)
- Var1 = Hello One
Var2 = Hello Two
Var3 = Hello Three
Var4 = Hello Four
Code: Select all
Str := "Hello One - Hello Two_Hello Three (Hello Four)"
Count := 0
Start := 1
while Pos := RegExMatch(Str, "[ a-zA-Z]+", Match, Start) {
Var%A_Index% := Trim(Match)
Start := Pos + StrLen(Match)
Count++
}
loop, % Count
Output .= "Var" A_Index ": " Var%A_Index% "`n"
MsgBox, % Output
Code: Select all
var := "Hello One - Hello Two_Hello Three (Hello Four)"
Arr := StrSplit(var,["-","_","("])
loop, % arr.maxindex()
MsgBox % Arr[a_index]
ExitApp
Code: Select all
Str := "Hello One - Hello Two_Hello Three (Hello Four)"
Var := []
Start := 1
while Pos := RegExMatch(Str, "[ a-zA-Z]+", Match, Start) {
Var.Push(Trim(Match))
Start := Pos + StrLen(Match)
}
for k, v in Var
Output .= "Var[" k "]: " v "`n"
MsgBox, % Output
Code: Select all
A := new biga() ; requires https://www.npmjs.com/package/biga.ahk
Str := "Hello One - Hello Two_Hello Three (Hello Four)"
array := A.split(Str, "/\s*[_\-\(\)]\s*/")
; => ["Hello One", "Hello Two", "Hello Three", "Hello Four", ""]
array := A.compact(array)
; => ["Hello One", "Hello Two", "Hello Three", "Hello Four"]
The reason I asked for Variables is because arrays confuse me. I don't use them often because I don't know how to deal with them. I'll try to use it but maybe I'll come back to this one if I can't figure it out. Anyway, I added some characters to the RegExMatch to suit my needs but there is one thing I couldn't figure out.boiler wrote: ↑22 Apr 2021, 00:19I think it would be better to use an array for the output, but here it is using separate variables since that's what you requested:
Code: Select all
Str := "Hello One - Hello Two_Hello Three (Hello Four)" Count := 0 Start := 1 while Pos := RegExMatch(Str, "[ a-zA-Z]+", Match, Start) { Var%A_Index% := Trim(Match) Start := Pos + StrLen(Match) Count++ } loop, % Count Output .= "Var" A_Index ": " Var%A_Index% "`n" MsgBox, % Output
Code: Select all
Str := "Hello One - Hello Two_Hello Three (Hello Four) _List One, Two & Three - String's End_"
Var := []
Start := 1
while Pos := RegExMatch(Str, "[ a-zA-Z0-9'&,]+", Match, Start) {
Var.Push(Trim(Match))
Start := Pos + StrLen(Match)
}
for k, v in Var
Output .= "Var[" k "]: " v "`n"
MsgBox, % Output
MsgBox % Var[Var.MaxIndex()]
exitapp
Yes:
Code: Select all
Str := "Hello One - Hello Two_Hello Three (Hello Four) _List One, Two & Three - String's End_"
Var := []
Start := 1
while Pos := RegExMatch(Str, "[ a-zA-Z0-9'&,]+", Match, Start) {
if (Trim(Match) != "")
Var.Push(Trim(Match))
Start := Pos + StrLen(Match)
}
for k, v in Var
Output .= "Var[" k "]: " v "`n"
MsgBox, % Output
MsgBox % Var[Var.MaxIndex()]
exitapp
Nice. Thank You. Now I just have to figure out how to incorporate this array into a GUI...boiler wrote: ↑22 Apr 2021, 23:31Yes:Code: Select all
Str := "Hello One - Hello Two_Hello Three (Hello Four) _List One, Two & Three - String's End_" Var := [] Start := 1 while Pos := RegExMatch(Str, "[ a-zA-Z0-9'&,]+", Match, Start) { if (Trim(Match) != "") Var.Push(Trim(Match)) Start := Pos + StrLen(Match) } for k, v in Var Output .= "Var[" k "]: " v "`n" MsgBox, % Output MsgBox % Var[Var.MaxIndex()] exitapp
Users browsing this forum: Joey5, mikeyww, Whazzzzzup15 and 267 guests