how to concatenate all the lines into one string

L

Li Chen

Hi all,

I am new to Ruby. I just wonder how I can concatenate all the lines from
one file and let them become one string.

Thanks,

Li
 
D

David Vallner

--------------enig704B06615D308C6BAA4889EA
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Li said:
I am new to Ruby. I just wonder how I can concatenate all the lines fro= m=20
one file and let them become one string.
=20

File.read("/path/to/file")

David Vallner


--------------enig704B06615D308C6BAA4889EA
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)

iD8DBQFFKUcBy6MhrS8astoRApBuAJ9cotzVe72utRSxh+ZRWtTtwfdtPwCeLbmR
GZaY4eVY8cPh3wlxvk9bv6E=
=DLmU
-----END PGP SIGNATURE-----

--------------enig704B06615D308C6BAA4889EA--
 
T

Thomas Adam

Hi all,
I am new to Ruby. I just wonder how I can concatenate all the lines from
one file and let them become one string.

How about:

a=File.open("/home/n6tadam/.xsession").read.gsub!('\n', ' ')

I've substituted the newlines for spaces -- but you can do whatever you
want with it.

-- Thomas Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top