(newbie) String / Array / ArrayedCollection
Daniel Vainsencher
daniel.vainsencher at gmail.com
Sun Jan 1 16:02:18 UTC 2006
There a method that streamlines efficient string creation called
stringContents, or streamContents, or contentString, or something like
that (don't remember).
theString _ String <methodName>: [:ws |
'A series of words to be shuffled' substrings shuffled
do: [:e | ws nextPutAll: e; nextPut: Character space]]
Daniel
David T. Lewis wrote:
> On Thu, Dec 29, 2005 at 11:32:53AM -0600, Tim Johnson wrote:
>
>>Quick question. What is the quick way to get an Array of strings back
>>into one String? Do I have to use a ReadStream / WriteStream?
>>
>>Example:
>>
>>'A series of words to be shuffled' substrings shuffled
>> -> #('of' 'series' 'words' 'A')
>>
>
>
> A WriteStream is usually a good way to do this, something like this:
>
> | ws |
> ws := WriteStream on: ''.
> 'A series of words to be shuffled' substrings shuffled
> do: [:e | ws nextPutAll: e; nextPut: Character space].
> ws contents allButLast
>
> But you can also iterate over a collection and accumulate the results
> using #inject:into:, for example like this:
>
> 'A series of words to be shuffled' substrings shuffled
> inject: nil
> into: [:str :e | (str ifNil: [''] ifNotNil: [str, ' ']), e]
>
> or this:
>
> ('A series of words to be shuffled' substrings shuffled
> inject: ''
> into: [:str :e | str, ' ', e]) allButFirst
>
> Dave
>
>
More information about the Squeak-dev
mailing list
|