AutoHotkey Community

It is currently May 27th, 2012, 4:17 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: February 19th, 2010, 12:40 am 
Offline

Joined: May 27th, 2009, 3:45 pm
Posts: 41
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2010, 4:38 am 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2010, 5:44 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 12:38 am 
Offline

Joined: May 27th, 2009, 3:45 pm
Posts: 41
Thank you, that worked.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Mickers, rbrtryn and 65 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group