From: David Vallner Date: 2006-11-17T23:41:23+09:00 Subject: Re: Nuby question - printing substring as non-ASCII --------------enig9F080F22A5592FC8DC73EBBB Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thomas Luedeke wrote: > I'm reading in a string of numbers, as follows: >=20 > " 1 45.3456 " >=20 > How do I write out the first non-whitespace element as a number? Ruby = > wants to express as it in ASCII, and the .to_i method doesn't seem to=20 > work on a substring. >=20 Doesn't seem to? Code please. Also, the following works for me: irb(main):009:0> " 1 45.3456 ".strip.split(/\s+/).map { |i| i.to_i } =3D> [1, 45] (Of course, to_i coerces to integers, so the body of the map block would have to be more complicated to get floats too.) David Vallner --------------enig9F080F22A5592FC8DC73EBBB Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFXcoNy6MhrS8astoRAq3QAJ9v6HUVmcq52eYSLBw5LH4PV+YJNgCeJdxM Hw5oaQdLaXXh4h+89kfq2Ws= =WH/P -----END PGP SIGNATURE----- --------------enig9F080F22A5592FC8DC73EBBB--