Robert Klemme
11/4/2008 3:27:00 PM
2008/11/4 Pe=F1a, Botp <botp@delmonte-phil.com>:
> From: John Griffiths [mailto:indiehead@gmail.com]
> # @s =3D "fdsdsf, dsfdsfsd fdsfdsfd dfsfds"
> # puts @s.gsub(',','').split( / */ ).join(',')
> # returns =3D> "fdsdsf,dsfdsfsd,fdsfdsfd,dfsfds"
>
> that is 3 meths
> try if one or 2 methods would do, eg,
>
>> @s.gsub(/,*\s+/,',')
> =3D> "fdsdsf,dsfdsfsd,fdsfdsfd,dfsfds"
This won't retain empty words. If you have to do this you can do
irb(main):005:0> "fdsdsf, dsfdsfsd fdsfdsfd dfsfds".gsub(/\s*[\s,]\s*/, ','=
)
=3D> "fdsdsf,dsfdsfsd,fdsfdsfd,dfsfds"
irb(main):006:0> "fdsdsf, dsfdsfsd fdsfdsfd dfsfds".gsub(/\s*[\s,]\s*/, ', =
')
=3D> "fdsdsf, dsfdsfsd, fdsfdsfd, dfsfds"
Here's another one
irb(main):008:0> "fdsdsf, dsfdsfsd fdsfdsfd dfsfds".gsub(/\W+/, ',')
=3D> "fdsdsf,dsfdsfsd,fdsfdsfd,dfsfds"
irb(main):009:0> "fdsdsf, dsfdsfsd fdsfdsfd dfsfds".gsub(/\W+/, ', ')
=3D> "fdsdsf, dsfdsfsd, fdsfdsfd, dfsfds"
Cheers
robert
--=20
remember.guy do |as, often| as.you_can - without end