String operators

Most arithmetic operators can be used on strings as well. In this case, they have string-specific behaviour.

Addition concatenates strings. If one of the arguments is not a string, it is converted into a string.

Yewslip> print "stri" + "ng", 1 + "a" + true
string 1a(true)

Subtraction removes a substring from a string if it is found. The substring nearest to the end of the string is removed if several match.

Yewslip> print "Hello world!" - " world!", "Hello" - "world", "forty-two" - "o"
Hello Hello forty-tw

Dividing a string by a substring splits the string into a list of strings on that substring.

Yewslip> print "a:b::c:" / ":"
[a, b, , c, ]

Yewslip> print "string" / "rin"
[st, g]

Dividing by an empty string splits the string into a list of characters.

Yewslip> print "string" / ""
[s, t, r, i, n, g]

Multiplying by a list by a string joins the list elements into a string.

Yewslip> print ["st", "r", "ing"] * "--"

Division and multiplication may be used as a simple way to globally replace a substring in a string.

Yewslip> print "characters" / "a" * ".A."