Tim Pease
4/18/2008 5:01:00 PM
On Apr 18, 2008, at 7:32 AM, Peter Loftus wrote:
> val =3D " hello ".sub(/\t/, ' ')
> puts val
>
> Cant covert tabbed spaces into regular single spaces
> Anyone have any ideas?
Use the String#tr comand
str =3D "string\twith\ttabs"
str.tr("\t", " ")
Blessings,
TwP
(and from the RDoc ...)
str.tr(from_str, to_str) =3D> new_str
Returns a copy of str with the characters in from_str replaced by the =20=
corresponding characters in to_str. If to_str is shorter than =20
from_str, it is padded with its last character. Both strings may use =20
the c1=97c2 notation to denote ranges of characters, and from_str may =20=
start with a ^, which denotes all characters except those listed.
"hello".tr('aeiou', '*') #=3D> "h*ll*"
"hello".tr('^aeiou', '*') #=3D> "*e**o"
"hello".tr('el', 'ip') #=3D> "hippo"
"hello".tr('a-y', 'b-z') #=3D> "ifmmp"