I have this example string:
Car (12), Street (2), Pedestrian (4), Tree (2)
With an AHK script I would like to filter out just the numbers and create the sum, which would be 20 in this case (12+2+4+2).
I've already made some progress:
Code: Select all
F2::
Clipboard := StrReplace(Clipboard, CHR(44), CHR(43)) ; Replace , with +
Clipboard := StrReplace(Clipboard, CHR(40)) ; Delete (
Clipboard := StrReplace(Clipboard, CHR(41)) ; Delete )
Clipboard := StrReplace(Clipboard, CHR(32)) ; Delete Spaces
Clipboard := RegExReplace(Clipboard, "\D+", "+") ; Replace all text+ by +
StringTrimLeft, Clipboard, Clipboard, 1 ; Delete first character from Clipboard (Because it starts with +)
return
12+2+4+2
Two questions:
1)
Are all those StrReplaces really necessary or is there an eleganter solution?
This one made a nice first impression:
Code: Select all
F5::
Clipboard := RegExReplace(Clipboard, "\D+") ; Delete everything which is not a number
return
In this case AHK would later count 1+2+2+4+2 instead of 12+2+4+2 - so I can't use this way.
2)
How to create a sum anyway?
If I try this, it works:
Code: Select all
F3::
a := 12+2+4+2 ; Create sum out of this
MsgBox, %a% ; It says 20 which is correct
return
Thanks for any help!
Regards