A thousand ways to say new line
Jump to navigation
Jump to search
TO-COMPLETE
Problem. You need to add a newline to your string. Dah! This is far more annoying than you may think because there is no universal consensus on what a newline character is. But, for starting we will call newlines the POSIX newlines, since in Unix systems newlines are extremely important.
A few examples
- first of all remember in Smalltalk you can go newline inside strings literals
'hello TYPE-RETURN-HERE '.
'hello ', (Character lf) asString.
'hello ', (Character newLineCharacter) asString.
'hello ' format: {Character lf. } .
'hello \n' printf: {}.
Using streams
Use the #newLine message on streams:
String streamContents: [:s | s nextPutAll: 'hello'; newLine]