dubstep
February 20, 2011, 3:48am
1
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 with a command. Then have it
sent to a .rb without changing them manually one by one.
scudco
February 20, 2011, 4:28am
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” [email protected]
Sent: Sunday, February 20, 2011 10:52 AM
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” [email protected]
Subject: Possible combination trick
scudco
February 20, 2011, 5:04am
3
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
scudco
February 20, 2011, 6:59am
4
sed ‘s/god/this/g’ < dogfile.rb
scudco
February 20, 2011, 1:48pm
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