ポリエチレンのgrep関数を使用すると、正規表現文字列を指定でき、すべての一致の区切り文字列が返されます。次に、その数値の正確なインスタンスを文字列に置き換えることができます。このスレッド(HamZa DzCyberDeVのおかげで)には、これがなぜであるかについての説明があります。
(これにはgrepスクリプトが必要です!)
ReplaceNumber(whattext, instance, replacewith){
numpos := grep(whattext, "[+-]?\d+(?:\.\d+)?",thisnumber,1,0,"|")
stringsplit, numpos, numpos,|
stringsplit, thisnumber,thisnumber,|
thispos := numpos%instance% ;get the position of the capture
thisinstance := thisnumber%instance% ;get the capture itself
thislen := strlen(thisinstance)
;now fetch the string that comes before the named instance
leftstring := substr(whattext, 1, thispos-1)
rightstring := substr(whattext, thispos+thislen, strlen(whattext))
returnthis := leftstring . replacewith . rightstring
return returnthis
}
msgbox, % replacenumber("7 men swap 55.2 or 55.2 for 100 and -100.", 5, "SWAPPED")
結果:
; 1--> SWAPPED men swap 55.2 for 100 and -100.
; 2--> 7 men swap SWAPPED or 55.2 for 100 and -100.
; 3 --> 7 men swap 55.2 or SWAPPED for 100 and -100.
; 4 --> 7 men swap 55.2 or 55.2 for SWAPPED and -100.
; 5 --> 7 men swap 55.2 or 55.2 for 100 and SWAPPED.
ありがとう、ポリエチレンとハムザ!