How to replace the comma sign of floating point numbers

Find, replace, find in files, replace in files, regular expressions

How to replace the comma sign of floating point numbers

Postby franco_fxp » Mon Jul 31, 2006 3:27 pm

Hi, everybody, one question: how to replace this (some commas)

wp_pos=(995,6089,0,8311,-262,6691)

to

wp_pos=(995.6089,0.8311,-262.6691)

I have over 400 lines in just one file txt.
Thanks
User avatar
franco_fxp
Newbie
 
Posts: 2
Joined: Sun Jul 30, 2006 11:00 pm

Re: How to replace the comma sign of floating point numbers

Postby Bego » Wed Aug 02, 2006 5:13 am

Hi,

what is the rule ?
Seems to be "change when value is between 0 and 1).
Replace with new stype perl regexp:
"([^0-9])0([,)])"
with:
"\10."

changes:
wp_pos=(0,6089,0,8311,-260,6691)
to:
wp_pos=(0.6089,0.8311,-260,6691)


rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: How to replace the comma sign of floating point numbers

Postby Mofi » Wed Aug 02, 2006 5:38 am

Hm, it looks like x,y,z coordinates with floating point numbers with wrong comma sign.

Try this UltraEdit style regular expression:

Find: ^(wp_pos=(-++[0-9]+^),^(-++[0-9]+,-++[0-9]+^),^(-++[0-9]+,-++[0-9]+^),^(-++[0-9]+)^)
Replace: ^1.^2.^3.^4

Or this one for Unix/Perl style:

Find: (wp_pos=\(-*\d+),(-*\d+,-*\d+),(-*\d+,-*\d+),(-*\d+\))
Replace: \1.\2.\3.\4


Note: I modified the subject of this thread to a much better and hopefully correct one.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: How to replace the comma sign of floating point numbers

Postby Bego » Wed Aug 02, 2006 6:11 am

Hi Mofi,

aint the rule just: replace "non-number, zero, komma " with "non-number, zero, point" ?

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: How to replace the comma sign of floating point numbers

Postby franco_fxp » Thu Aug 03, 2006 2:09 pm

Thank you guys!, the new subject is correct, they are xyz coordinates, now I'will try.
Franco
User avatar
franco_fxp
Newbie
 
Posts: 2
Joined: Sun Jul 30, 2006 11:00 pm


Return to Find/Replace/Regular Expressions