Smalltalk, newline character

smalltalk, tokenize

Solution

The newline delimiter is typically the carriage return, i.e., `Character cr`, or as others mentioned, in a string, `String cr`. If you wanted to support all standard newline formats, just include both standard delimiters, for example:

string := 'smalltalk is
a lot of fun.'.

string findTokens: String cr, String lf.

Since you now mention you're using VisualWorks, the above won't work unless you have the "squeak-accessing" category loaded (which you probably won't unless you're using Seaside). You could use a regular expression match instead:

'foo
bar' allRegexMatches: '[^', (String with: Character cr), ']+'

Problem

Does anybody know what's the newline delimiter for a string in smalltalk? I'm trying to split a string in separate lines, but I cannot figure out what's the newline character in smalltalk. ie. ``` string := 'smalltalk is a lot of fun. ok, it's not.' I need to split it in: line1: smalltalk is line2: a lot of fun. line3: ok, it's not. ``` I can split a line based on any letter or symbol, but I can't figure out what the newline delimter is. OK here is how I'm splitting the string based on commas, but I cannot do it based on a new line.

Original source

Related problems