Appending a character to a string

Alan Lovejoy squeak-dev.sourcery at forum-mail.net
Sun Feb 11 21:06:29 UTC 2007


<Damien Cassou>
Often, I want to concatenate a character to a string :

self doSomethingWith: myString, Character cr, anotherString.


However, #, only works with collections. I'm obliged to use #copyWith:
instead. Is there a pattern to do this without using Streams ?
</Damien Cassou>

A conceptual example:

SequenceableCollection>>& anElementOrSequenceableCollection
	"#(1 2 3) & 4"" -> #(1 2 3 4)"
	"#(1 2 3) & #(4 5 6)"" -> #(1 2 3 4 5 6)"

	^anElementOrSequenceableCollection appendToSequenceableCollection:
self

SequenceableCollection>>appendToSequenceableCollection:
aSequenceableCollection
	^aSequenceableCollection, self

Object>>appendToSequenceableCollection: aSequenceableCollection
	^aSequenceableCollection copyWith: self





More information about the Squeak-dev mailing list