Tarch wrote:
Hi,
I think it would be clearer in this two points with
Code:
temp := SubStr(Options, 2, -1)
Code:
temp := RegExReplace(Options, "^,?(.*?),?$", "$1")
I disagree. Using SubStr() is shorter, clearer
and more efficient. We know there will
always be start and end commas in "Options", so there is no need to use regular expressions (or the "?" quantifier.)
Quote:
and this
Code:
StringReplace, Options, Options, `,%Number%`,, `,
with
Code:
Options := RegExReplace(Options, ",?" . Number)
The point of having commas on both sides of
every number is to remove ambiguity when, for example, one number is a subset of another. For example: ",?1" would match the "1" in ",210" (because the comma is optional)... However, I realise now that there should
never be ambiguity, because
- a larger number can't be a subset of a smaller number ("x" can't contain "xy"), and
- the indices are in ascending order (left->right),
- so AHK will always find the smaller number first!
So, you could...
Code:
; replace:
Options = ,
; with:
Options = ; no starting comma needed
; replace these two lines:
temp := SubStr(Options, 2, -1)
Loop, Parse, temp, `,
; with:
Loop, Parse, Options, `, ; no need to remove anything - no need for temp
; and this:
StringReplace, Options, Options, `,%Number%`,, `,
; with
StringReplace, Options, Options, %Number%`, ; remove N, (no starting comma required)
At any rate, I much prefer the second method I posted (using Asc() and Chr()). It's more compact, more efficient, and cleverer.

Quote:
Code:
...
Options := SubStr(Options, 1, Pos-1) . SubStr(Options, Pos+1)
this with regex can be:
Code:
...
Options := RegExReplace(Options, Tmp)
*sigh*. Why are you using RegExReplace? Tmp can potentially be
any character. Because you haven't escaped it (e.g. "\Q" . Tmp . "\E"), if Tmp is a regex-reserved character, the script could crash. Granted, that isn't likely (there'd have to be a lot of windows), but it's possible. More to the point, you haven't specified a regular expression, so you should be using StringReplace, not RegExReplace.
There are two reasons I believe SubStr() . SubStr() is (marginally) more efficient:
- *Replace needs to first search for the character, whereas we already know the position.
- The *Replace method requires the use of a Tmp variable.