I'm currently working on an exercise in squeak-Smalltalk. I want to split a string that behaves somewhat like split functions in Java or python, but hardly found anything on the internet. Any suggestions please? How can I implement it?
Thank you!
Unfortunately no, it seems there is no split
or splitBy:
message in squeak (unlike Pharo...) so I implemented such a method by myself.
split: aSentence
|count str strArr |
str := aSentence.
count := ((aSentence select: [:a | a = $ ])) size.
strArr := OrderedCollection new.
[count >= 0]
whileTrue: [
strArr add: (str copyFrom: 1 to: (str indexOf: $ ifAbsent: [str size + 1]) - 1).
str := str copyFrom: ((str indexOf: $ ) + 1) to: (str size).
count := count - 1.
].
^strArr