split:

J J azreal1977 at hotmail.com
Sat Sep 30 10:23:57 UTC 2006


And here is my vote for split.


>From: Keith Hodges <keith_hodges at yahoo.co.uk>
>Reply-To: The general-purpose Squeak developers 
>list<squeak-dev at lists.squeakfoundation.org>
>To: The general-purpose Squeak developers 
>list<squeak-dev at lists.squeakfoundation.org>
>Subject: Re: split:
>Date: Sat, 16 Sep 2006 02:20:17 +0100
>
>The question as to whether split: should work with Strings or Regex's is 
>something that should be handled with a double dispatch. If you feed it a 
>String it should use a string if you feed it a Regex then it will use a 
>Regex.
>
>eg := 'Now is the time for all good men to come to the aid of the  party'.
>
>eg splitOnEvery: 'the'
>eg splitOnEvery: ( '+[\s]' asRegex ).
>eg splitOnEvery: $e.
>#(1 2 3 4 5 6 7 8 9) splitOnEvery: #(4).
>#(1 2 3 4 5 6 7 8 9) splitOnEvery: #(4 5 6).
>#(1 2 3 4 5 6 7 8 9) splitOnEvery: [ :n | n isPrimeNumber ]
>
>SequencableCollection>>splitOnEvery: aSpliter
>^aSpliter  splitUp:  self
>
>aRegex>>splitUp: aString.
>...regex implementation
>aString>>splitUp: aString.
>...string implementation
>aCharacter>>splitUp: aString.
>...character implementation
>aSequencableCollection>>splitUp: aSequencableCollection
>... generic collection implementation.
>aMonadicBlock>>splitOnEvery: thing
>^ thing splitUsing: aBlock.
>
>more ideas
>
>Keith
>
>
>
>
> >In my viewer I saw two spaces at "the  party".
> >So what should happen for #split: on a single space.
> >Should there be an extra item with value nil or an
> >empty string? Or should there be no extra item?
>
>I think that the convention is to return an empty string. -> #('the' '' 
>'party')
>
>
>
>
>
>___________________________________________________________ Yahoo! 
>Messenger - NEW crystal clear PC to PC calling worldwide with voicemail 
>http://uk.messenger.yahoo.com
>





More information about the Squeak-dev mailing list