Recipe: Doing something with each line in a file
Last updated at 11:06 am UTC on 31 May 2016
You want to process a text file line by line. You don't want to worry about different line end characters in different operating systems.
Create an instance of a MultiByteFileStream on the file:
file := FileStream fileNamed: 'test.txt'.
[file atEnd] whileFalse:
[line := file nextLine. "Process the line"]
DiscussionThe MultiByteFileStream does its job in a platform independent way.
Regular Expressions in Squeak if you want to do more complicated things to each line.