Possible combination trick

A

Adam Abc

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.
 
Ä

何平

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
 
J

J. K.

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
 
S

Stu

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

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

Tadeusz Bochan

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
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top