This seems easiest to me:
Code: Select all
keys := map()
keys["MAXBUF"] := 4000
keys["MINBUF"] := 100
ustring := "MyValue = MAXBUF;\nAltValue = MINBUF;"
for k, v in keys
ustring := StrReplace(ustring, k, v)
MsgBox ustring ; ustring result: "MyValue = 4000;\nAltValue = 100;"
Or so the main part of your code would look exactly as you have it:
Code: Select all
keys := map()
keys["MAXBUF"] := 4000
keys["MINBUF"] := 100
ustring := "MyValue = MAXBUF;\nAltValue = MINBUF;"
ustring := replaceKeys( ustring, keys )
MsgBox ustring ; ustring result: "MyValue = 4000;\nAltValue = 100;"
return
replaceKeys(str, keys) {
for k, v in keys
str := StrReplace(str, k, v)
return str
}
Coiler wrote: ↑
I'm new to using AHK regex - does it support anything like this? Or would it be better to parse the string myself?
RegEx can do this, but it's not necessary. StrReplace is preferred when it is capable.