Appending a character to a string

Joshua Gargus schwa at fastmail.us
Sun Feb 11 18:06:33 UTC 2007


Tweak allows this (at least the Croquet version of Tweak).  In the  
Tweak-Hacks package, you find the method:

, anObject
	^ self copyReplaceFrom: self size + 1
		  to: self size
		  with: anObject asString

The nice thing is that it doesn't just work for characters.  You can  
append *anything* to a string.

I've found this to be very handy, and haven't run into any subtle  
bugs/problems as a result.  However, my primary use of the construct  
is for logging, which isn't a very demanding application.

Josh



On Feb 11, 2007, at 9:00 AM, Damien Cassou wrote:

> Hi,
>
> 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 ?
>
> Would it be desirable to enhance #, to allow concatenation of a single
> element ?
>
> Bye
>
> -- 
> Damien Cassou
>
>




More information about the Squeak-dev mailing list