Possible combination trick

Discussion in 'Ruby' started by Adam Abc, Feb 20, 2011.

  1. Adam Abc

    Adam Abc Guest

    Let's say I have this:

    to you the dog
    to that the dog
    was to the dog
    and you the dog
    you and the dog
    and that the dog
    and he the dog
    he and the dog
    and was the dog

    and I want this

    to you and this
    to that and this
    was to and this
    and you and this
    you and and this
    and that and this
    and he and this
    he and and this
    and was and this

    How do you change every the dog to and this? Then have it sent to a .rb
    file.

    --
    Posted via http://www.ruby-forum.com/.
     
    Adam Abc, Feb 20, 2011
    #1
    1. Advertising

  2. if you are talking about replacing in strings, most text editors have
    search/replace functions to.
    want to do it in ruby? take a look at String.gsub

    --------------------------------------------------
    From: "Adam Abc" <>
    Sent: Sunday, February 20, 2011 10:52 AM
    Newsgroups: comp.lang.ruby
    To: "ruby-talk ML" <>
    Subject: Possible combination trick

    > Let's say I have this:
    >
    > to you the dog
    > to that the dog
    > was to the dog
    > and you the dog
    > you and the dog
    > and that the dog
    > and he the dog
    > he and the dog
    > and was the dog
    >
    > and I want this
    >
    > to you and this
    > to that and this
    > was to and this
    > and you and this
    > you and and this
    > and that and this
    > and he and this
    > he and and this
    > and was and this
    >
    > How do you change every the dog to and this? Then have it sent to a .rb
    > file.
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >
     
    何平, Feb 20, 2011
    #2
    1. Advertising

  3. Adam Abc

    J. K. Guest

    Adam Abc wrote in post #982724:
    > Let's say I have this:
    >
    > to you the dog
    > to that the dog
    > was to the dog
    > and you the dog

    ...

    yer a friggin poet, man - beautiful shite, really... love it. and
    the last post is your answer. gsub is the trick.

    keep writing to you and that dog...

    -jk

    --
    Posted via http://www.ruby-forum.com/.
     
    J. K., Feb 20, 2011
    #3
  4. Adam Abc

    Stu Guest

    [Note: parts of this message were removed to make it a legal post.]

    sed 's/god/this/g' < dogfile.rb

    On Sat, Feb 19, 2011 at 10:04 PM, J. K. <> wrote:

    > Adam Abc wrote in post #982724:
    > > Let's say I have this:
    > >
    > > to you the dog
    > > to that the dog
    > > was to the dog
    > > and you the dog

    > ...
    >
    > yer a friggin poet, man - beautiful shite, really... love it. and
    > the last post is your answer. gsub is the trick.
    >
    > keep writing to you and that dog...
    >
    > -jk
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >
     
    Stu, Feb 20, 2011
    #4
  5. If only more problems were like this ... life wouldn't be such a dog !

    print DATA.read.gsub(/the +dog/,'and this')
    __END__
    to you the dog
    to that the dog
    was to the dog
    and you the dog
    you and the dog
    and that the dog
    and he the dog
    he and the dog
    and was the dog

    --
    Posted via http://www.ruby-forum.com/.
     
    Tadeusz Bochan, Feb 20, 2011
    #5
    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. Valentin Tihomirov
    Replies:
    3
    Views:
    562
    Jonathan Bromley
    Oct 28, 2003
  2. Paul
    Replies:
    1
    Views:
    362
    Peter Blum
    Nov 29, 2003
  3. =?Utf-8?B?TmlnZWwgQXJtc3Ryb25n?=

    combination of SiteMap and cookieless sessions/forms based securit

    =?Utf-8?B?TmlnZWwgQXJtc3Ryb25n?=, Nov 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    563
    =?Utf-8?B?TmlnZWwgQXJtc3Ryb25n?=
    Nov 15, 2005
  4. Mir Nazim
    Replies:
    8
    Views:
    744
    Mir Nazim
    Jul 25, 2006
  5. AAA

    possible combination of numbers

    AAA, Sep 2, 2006, in forum: C Programming
    Replies:
    1
    Views:
    359
    Spiros Bousbouras
    Sep 2, 2006
Loading...

Share This Page