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
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
Now you need to extract information from that text. How will you do
There a basically two ways: by position or by pattern. So you need to
out what about the file is always the same no matter which students
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
to find the rest. So something like
match = /\*Number\s*:\*(\d+)/.match(text)
The characters in between the /…/ are a Regular Expression. Look that
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
Because of the (\d+) we have capture the digits in the first match
number = match
Now you should be able to read up on the things I suggested and work out
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
ING DIRECT Conto Arancio. 4,20% per 12 mesi, zero spese, aprilo in due
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=11921&d=29-12