Concat strings with separating linefeeds

classic Classic list List threaded Threaded
1 message Options
Ankh'nAton Ankh'nAton
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Concat strings with separating linefeeds

Hi,

inserting '\n' into any string does not work in Amber.

It does not work in JavaScript either. You have to surround \n wih
double quotes instead, like "any text\n". But, in Smalltalk the double
quote is reserved for the purpose of source documentation. So, you
cannot use it that way.

Other Smalltalks know about a global object 'Crlf' which expands to
the ASCII characters 13 and 10, to be appended to a given string using
the ',' operator. I looked at the 'Number' class for a method
'asCharacter' to follow that pattern, but it wasn't there ;) - It's
easily added with the Browser. To the 'Number' class add the instance
method 'asCharacer'

asCharacter
        < return String.fromCharCode(this); >

Now, to concat a string with separating linefeeds, go like...

crlf := 13 asCharacter, 10 asCharacter.
str := 'My string', crlf, 'I love it!', crlf.

Have a Smalltalk ;)
Loading...