Forum: Ruby Re: add to words syntaxes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dani (Guest)
on 2006-03-16 15:08
(Received via mailing list)
Hi again!
Thanks for ALL your support, especially for Carlos. now it works fine!
Only one more question and I leave this theme.
What is if I in my TXT file the parameters repeat self?
So I mean:
0608A;
Teszt Kft;
33445566222;
;
20060101;
20060131;
0A0001C002A 33445566222
0A0001C007A Teszt kft

0608M
Oscar Wild
123456789
;
20060101;
20060131;
0A0001C002A 33445566222
0A0001C007A Teszt kft

etc.. So I need, that on the end of the first paragraph it looks for the
second. How can I do this? With the same syntax, same file.
Regards:

Daniel
Carlos (Guest)
on 2006-03-16 17:18
(Received via mailing list)
Dani wrote:
[...]
>
> second. How can I do this? With the same syntax, same file.
> Regards:

# Set the "input record delimiter" to "paragraph". This is
# a special case and you weren't expected to know it beforehand :)

original_delimiter = $/
$/ = ""

# ... read the "lines" (chunks of text between <newline><newline>) ...

chunks = ARGF.readlines

# ... and restore the IRS to <newline>

$/ = original_delimiter

# now extract individual lines from each chunk and process them as
before

chunks.each do |chunk|
   lines = chunk.split($/)
   ... < the previous code > ...
end

HTH - (not tested)
This topic is locked and can not be replied to.