 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Michael2222
Joined: 27 May 2009 Posts: 39
|
Posted: Thu Feb 18, 2010 11:40 pm Post subject: Bug in number conversion program |
|
|
Hello,
I want to take a number with a German format in a cell (for instance 1.234,56) and convert it to a number with a US format (for instance 1,234.56).
The program shown below works fine when there are just numbers in the program, but if there is text, it also puts a "." before the number being converted. I'm not sure why.
Thanks in advance for any hints or any suggestions on changing the code.
| Code: |
SendInput, ^x
Clipwait
segment= %clipboard%
new:=regexreplace(segment, "(\d*)[\, ](\d{1,2})", "$1.$2")
new:=regexreplace(new, "(\d*)[\. ](\d\d\d)", "$1,$2")
clipboard=%new%
SendInput, ^v
|
|
|
| Back to top |
|
 |
randallf
Joined: 06 Jul 2009 Posts: 678
|
Posted: Sat Feb 20, 2010 3:38 am Post subject: |
|
|
If it's just flipping comma and period,
| Quote: | StringReplace, String, String, ., `, ;not sure if you need escape char`
StringReplace, String, String, `, . ;again not sure if you need escape char |
Oh right, you could also use global variables, I'm not sure if A_period exists, but,
| Quote: | StringReplace, String, String, ., %A_comma%
StringReplace, String, String, `, . ;again not sure if you need escape char |
|
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Sat Feb 20, 2010 4:44 am Post subject: |
|
|
The star matches zero of more so that's probably part of the problem with the leading period, try this:
| Code: | SendInput, ^x
Clipwait
segment= %clipboard%
new:=regexreplace(segment, "(\d+)[\, ](\d{1,2})", "$1.$2")
new:=regexreplace(new, "(\d+)[\. ](\d\d\d)", "$1,$2")
clipboard=%new%
SendInput, ^v |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
Michael2222
Joined: 27 May 2009 Posts: 39
|
Posted: Sat Feb 20, 2010 11:38 pm Post subject: |
|
|
| Thank you, that worked. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|