AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bug in number conversion program

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Michael2222



Joined: 27 May 2009
Posts: 39

PostPosted: Thu Feb 18, 2010 11:40 pm    Post subject: Bug in number conversion program Reply with quote

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
View user's profile Send private message
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Sat Feb 20, 2010 3:38 am    Post subject: Reply with quote

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
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Sat Feb 20, 2010 4:44 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Michael2222



Joined: 27 May 2009
Posts: 39

PostPosted: Sat Feb 20, 2010 11:38 pm    Post subject: Reply with quote

Thank you, that worked.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group