Adding to a string – append and insert

To insert something at the beginning of a string, use insert:

str: "painting"insert str "beautiful "str ;== "beautiful painting"

Here is how you can insert a substring into a string at a certain position:

str: "abcdefg"insert at str 3 "ONE"     ;== "cdefg"str ;== "abONEcdefg"; the same can be done with:insert find str "c" "ONE" ;== "cdefg"str                       ;== "abONEcdefg"

Again, for readability, you could write insert (find str "c") "ONE".

By now, you know how to use append to add something to the tail of a string, in other words, to concatenate two strings:

str: "Red"           ;== "Red"append str "100"     ;== "Red100"append str [1 0 0]   ;== "Red100100"

Note that, in the last example, a series is automatically converted to a ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.