Programmer's Reference

Line delimiters

By default, a stream uses the platform file system's line delimiter for operations such as cr and nextLine. A string representing the current line delimiter can be obtained by sending the lineDelimiter message to a file stream instance, and can be changed to an arbitrary string by sending the lineDelimiter: message. This makes it possible to adopt a single platform's file convention as the standard for all platforms, or to use nextLine to read files written on other platforms. The following table lists the line delimiter constants defined in the CldtConstants pool dictionary:

Table 9. Line Delimiter constants in the CldtConstants pool dictionary

Pool variable Description
LineDelimiter The default platform line delimiter
PMLineDelimiter The line delimiter used by OS/2 Presentation Manager
UNIXLineDelimiter The line delimiter used by AIX and OS/390(R)
WINLineDelimiter The line delimiter used by MS-DOS/Windows

The following example demonstrates the use of the lineDelimiter: message and line delimiter constants, as well as their effect on the cr message:

| file |
file := CfsReadWriteFileStream openEmpty: 'testing.txt'.
 
"Use OS/2 line delimiter"
file lineDelimiter: PMLineDelimiter.
file cr; nextPutAll: '<-os/2 line delimiter'.
 
"Set back to default line delimiter"
file lineDelimiter: LineDelimiter.
file cr; nextPutAll: '<-default line delimiter'.
 
"Use an arbitrary line delimiter"
file lineDelimiter: '[end of line]'.
file cr; nextPutAll: '<-arbitrary line delimiter'.
file close.
Tip:
Use upToAll: and skipToAll: to scan up to various special character sequences. This is better than changing the line delimiter to the special sequence with lineDelimiter: and then using nextLine.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]