[squeak-dev] Hyphenation puzzle/exercise
Jon Hylands
jhylands at gmail.com
Thu Mar 9 20:34:39 UTC 2023
This works:
| s out |
s := 'eg11dc5cad154625885bc70d4f42818e' readStream.
out := (String new: 20) writeStream.
#( 8 4 4 4 ) do: [:count | out nextPutAll: (s next: count); nextPut: $-].
out nextPutAll: (s upToEnd); contents
It has the advantage of not depending on #joinSeparatedBy:, so it works in
versions of Smalltalk that don't include it (like Cuis).
- Jon
On Thu, 9 Mar 2023 at 14:55, Tim Johnson <digit at sonic.net> wrote:
> Hi all,
>
> I was toying with different ways to add hyphens to a string in a
> specific pattern, like for a UUID. Here's what I came up with:
>
> | s oc |
> s := 'eg11dc5cad154625885bc70d4f42818e' readStream.
> oc := OrderedCollection new.
> #( 8 4 4 4 12 ) do: [:count | oc add: (s next: count)].
> oc joinSeparatedBy: $-
>
> " 'eg11dc5c-ad15-4625-885b-c70d4f42818e' "
>
>
> Does anyone have any more graceful or clever ways of accomplishing this?
>
> Thanks,
> Tim
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20230309/382e4fda/attachment.html>
More information about the Squeak-dev
mailing list
|