From: Intransition Date: 2011-11-11T15:15:07+09:00 Subject: Re: important qution on ruby ------=_Part_470_17234674.1320992103188 Content-Type: multipart/alternative; boundary="----=_Part_471_21317169.1320992103189" ------=_Part_471_21317169.1320992103189 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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. ------=_Part_471_21317169.1320992103189 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 hav= e 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 d= o 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 studen= ts 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 t= he *Number :* part so as to find the rest. So something like

 &= nbsp;    match =3D /\*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" ch= aracters or to indicate a special type of character, e.g. \d means any digi= t.

Because of the (\d+) we have capture the digits in the first matc= h element, so:
 
      number =3D 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.

------=_Part_471_21317169.1320992103189-- ------=_Part_470_17234674.1320992103188--