How to get all items from text from an ordered collection
simple question i got
|list string|
list:= #('ab' 'efghij' 'lmnopqrst'). "Ordered collection"
list do:[:each| "string with:each" i know this is not right how do i add items ].
I tried to use streams too and it gave me back this "ordered collection ('ab' 'efghij' 'lmnopqrst')"
I only need one text with
'abc efghij lmnopqrst '
source to share
Object
the class has defined a message #asString
that reads:
"Answer a string that represents the receiver."
So you can do:
| aList aStringsList |
aList := #('ab' 'efghij' 'lmnopqrst'). "Array"
aStringsList := aList collect: [ :each | each asString ]
And it aStringsList
will be Array
String
, the return call #asString
in each of the aList
members.
If you want to combine all of them into one String
, you can use the #inject:into:
collection method instead #collect:
:
aList inject: '' into: [ :text :each | text , each asString , ' ' ]
If you type this you get the 'ab efghij lmnopqrst '
one you want :)
source to share