how to concatenate all the lines into one string

Discussion in 'Ruby' started by Li Chen, Oct 8, 2006.

  1. Li Chen

    Li Chen Guest

    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


    --
    Posted via http://www.ruby-forum.com/.
    Li Chen, Oct 8, 2006
    #1
    1. Advertising

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

    Li Chen wrote:
    > 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--
    David Vallner, Oct 8, 2006
    #2
    1. Advertising

  3. Li Chen

    Thomas Adam Guest

    On Mon, Oct 09, 2006 at 03:36:43AM +0900, Li Chen wrote:
    > 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

    --
    "If I were a witch's hat, sitting on her head like a paraffin stove, I'd
    fly away and be a bat." -- Incredible String Band.
    Thomas Adam, Oct 8, 2006
    #3
  4. Li Chen

    Marc Heiler Guest

    Marc Heiler, Oct 8, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. idiotprogrammer
    Replies:
    4
    Views:
    1,136
    Joseph Kesselman
    Mar 5, 2007
  2. Robin Wenger
    Replies:
    11
    Views:
    3,629
  3. Magnus
    Replies:
    8
    Views:
    211
    Andy Baxter
    Jan 13, 2004
  4. Tony
    Replies:
    5
    Views:
    738
  5. Carlos

    Concatenate/De-Concatenate

    Carlos, Oct 12, 2012, in forum: VHDL
    Replies:
    10
    Views:
    877
Loading...

Share This Page