Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Possible combination trick

Reply
Thread Tools

Possible combination trick

 
 
Adam Abc
Guest
Posts: n/a
 
      02-20-2011
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/.

 
Reply With Quote
 
 
 
 
何平
Guest
Posts: n/a
 
      02-20-2011
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" <(E-Mail Removed)>
Sent: Sunday, February 20, 2011 10:52 AM
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <(E-Mail Removed)>
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/.
>
>


 
Reply With Quote
 
 
 
 
J. K.
Guest
Posts: n/a
 
      02-20-2011
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/.

 
Reply With Quote
 
Stu
Guest
Posts: n/a
 
      02-20-2011
[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. <(E-Mail Removed)> 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/.
>
>


 
Reply With Quote
 
Tadeusz Bochan
Guest
Posts: n/a
 
      02-20-2011
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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
possible combination of numbers AAA C Programming 1 09-02-2006 11:51 AM
Generating all possible combination of elements in a list Mir Nazim Python 8 07-25-2006 07:28 PM
is there a hardware / driver combination out there the lets win2k connect to the network before login?? christiane kewitz Wireless Networking 1 02-13-2005 01:08 AM
Generating combination signal from within clocked clocked block Valentin Tihomirov VHDL 3 10-28-2003 08:56 AM
Re: regarding Cisco Pix, DMZ and NAT combination Michael Hatzis Cisco 0 07-09-2003 12:46 AM



Advertisments