[Question]Yet another question. (Collections)
Bob Arning
arning at charm.net
Thu May 11 17:41:55 UTC 2000
On Thu, 11 May 2000 18:26:39 +0200 Karl Ramberg <karl.ramberg at chello.se> wrote:
>Thanks for the answer. That helps a little but what I want to do is
>when I have a collection of say
>
> col := #('1' '2' '3' '4') asOrderedCollection
> numbers := col collect: [ :each | each asNumber ]
>
>Then some code so I end up with a integer with value 1234.
Karl,
#('1' '2' '3' '4') inject: 0 into: [ :sum :each | sum * 10 + each asNumber]
or
(#('1' '2' '3' '4') inject: '' into: [ :sum :each | sum , each]) asNumber
or
(#('1' '2' '3' '4') printString select: [ :each | each isDigit]) asNumber
Cheers,
Bob
More information about the Squeak-dev
mailing list
|