Da: Intransition [mailto:[email protected]]
Inviato: venerd 11 novembre 2011 07:15
A: ruby-talk ML; [email protected]
Cc: ruby-talk ML; [email protected]
Oggetto: Re: important qution on ruby
Break the problem down. What is given? First a file. So you need to
“read”
the “File”. Look up File.read
and read about that.
Okay if you have done that, let’s say you have read the file into a
variable
called text
.
Now you need to extract information from that text. How will you do
this?
There a basically two ways: by position or by pattern. So you need to
figure
out what about the file is always the same no matter which students
record
it is and use that as a guide to locate the other information.
For example the number appears like so:
Number : 20085252
You could get this information by matching against the Number : part
so as
to find the rest. So something like
match = /\*Number\s*:\*(\d+)/.match(text)
The characters in between the /…/ are a Regular Expression. Look that
up
and read about them. Notice we had to use \
in some places to “escape”
characters or to indicate a special type of character, e.g. \d means any
digit.
Because of the (\d+) we have capture the digits in the first match
element,
so:
number = match[1]
Now you should be able to read up on the things I suggested and work out
how
to do it for the rest of the information.
And have fun. It’s a like a puzzle, not a chore.
–
Caselle da 1GB, trasmetti allegati fino a 3GB e in piu’ IMAP, POP3 e
SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f
Sponsor:
ING DIRECT Conto Arancio. 4,20% per 12 mesi, zero spese, aprilo in due
minuti!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=11921&d=29-12