Sorry, I didn't read your first posting fully. My solution will not
work for the case of 482.600.

Pepe

On Feb 28, 10:12 am, pepe <[email protected]> wrote:
> string = '10.0'
> string.sub!(/\.\d+/, '')
>
> This will replace in place (sub!) any dot (\.) followed by at least
> one number (\d+) with nothing ('').
>
> Pepe
>
> On Feb 27, 4:37 pm, northband_101 <[email protected]> wrote:
>
> > Awesome - this is a start - I'll take it from here.
>
> > Thanks!
>
> > On Feb 27, 4:14 pm, Rob Biedenharn <[email protected]>
> > wrote:
>
> > > On Feb 27, 2009, at 2:47 PM, northband wrote:
>
> > > > Hi -
>
> > > > I would like to use gsub() to strip decimals with trailing zeros from
> > > > a string.  My string looks like this:
> > > > --
> > > > 19.0 " / 482.600 mm
> > > > --
>
> > > > I would like to end up with this:
> > > > --
> > > > 19 " / 482.6 mm
> > > > --
>
> > > > Anyone have a regular expression that can do this?
>
> > > > Thanks!
>
> > > It depends on how you make the string.
>
> > > "19.0".sub(/\.?0+\z/,'')    #=> "19"
> > > "482.600".sub(/\.?0+\z/,'') #=> "482.6"
>
> > > If you replace \z with (\D|\z) and substitute '\1', it might work.  
> > > (You can try it out yourself.)
>
> > > -Rob
>
> > > Rob Biedenharn          http://agileconsultingllc.com
> > > [email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to