[Newbies] [Q] How should one concatenate Strings?

Damien Cassou damien.cassou at laposte.net
Wed May 10 19:12:08 UTC 2006


> Since using a stream to construct a collection is a very common task, 
> there is a nice helper construct for this:
> 
>     String streamContents: [:stream |
>         1 to: 10000 do: [:i | stream print: i]]
> 
> This spares you to declare one temporary variable and is overall more 
> readable.
> 
> Also, I used the stream's #print: method which will append a string 
> representation of its argument - you could, of course, use #nextPutAll:, 
> too.
> 
> Btw, do *not* put parens around "1 to: 10000". Of course this works, but 
> writing "1 to: 10000 do:" uses the #to:do: message which is way more 
> efficient, and a tiny bit shorter to read, too.

Thank you for all this advices. It will help.

-- 
Damien Cassou



More information about the Beginners mailing list