I am trying to look for a a given string in a text and once i find the
string
I want to be able to store a string that comes after it.
For example I would look for a String "JUNE" and once I find "JUNE" in
the text
I want to store the string that follows JUNE in a variable x. This
string should be 7 characters. So if the text has "JUNE seventh 2012". I
want to be able to store the string seventh in a variable x. Such that
puts x will print seventh on the screen.
This is what I have so far but this only prints the string that I am
looking for. I would like to be able to print the string that comes
after the string I am looking for.
file_names = ['Document.txt']
file_names.each do |file_name|
text = File.read(file_name)
You need a regular expression with a capturing group.
Cheers
robert
···
On Tue, Jul 9, 2013 at 7:44 PM, dJD col <lists@ruby-forum.com> wrote:
I am trying to look for a a given string in a text and once i find the
string
I want to be able to store a string that comes after it.
For example I would look for a String "JUNE" and once I find "JUNE" in
the text
I want to store the string that follows JUNE in a variable x. This
string should be 7 characters. So if the text has "JUNE seventh 2012". I
want to be able to store the string seventh in a variable x. Such that
puts x will print seventh on the screen.
This is what I have so far but this only prints the string that I am
looking for. I would like to be able to print the string that comes
after the string I am looking for.
file_names = ['Document.txt']
file_names.each do |file_name|
text = File.read(file_name)