Reputation: 461
I have string like "Hello World". I need to split this string to Hello
, World`` using space delimiter in Smalltalk.
In Java the code looks as follows
String message = "Hello world"
message.split(' ');
How do I do this in Smalltalk?
Upvotes: 1
Views: 5269
Reputation: 436
in a very buggy version of smalltalk on another site, this works but spliton does not.
s := 'Hello World' substrings '\n'.
n := s at: 2.
Transcript show: 's at 2='.
Transcript show: n.
Transcript show: ''; cr.
Upvotes: 1
Reputation: 801
Closer to Java:
'Hello World' splitOn: Character space.
also works with:
'Hello World' splitOn: ' '.
or (more funky):
[ :each | each isSeparator ] split: 'Hello World'.
'Hello World' splitOn: [ :each | each isSeparator ].
Upvotes: 3
Reputation: 13386
| message parts |
message := 'Hello world'.
parts := message substrings. "this is an array"
Transcript
show: parts first;
show: parts last
Or to define delimiter: message substrings: ' '
Upvotes: 4