strings

A string is a sequence of characters. These strings can be manipulated in various ways to produce printed output. One enters a string by surrounding them with quotation marks.

i1 : "abcdefghij"

o1 = abcdefghij

o1 : String

Strings may contain newline characters.

i2 : "abcde
     fghij"

o2 = abcde
fghij

o2 : String

Strings, like anything else, can be assigned to variables.

i3 : x = "abcdefghij"

o3 = abcdefghij

o3 : String

There are escape sequences which make it possible to enter special characters:
           \n             newline
           \f             form feed
           \r             return
           \\             \ 
           \"             "
           \t             tab
           \xxx           ascii character with octal value xxx

i4 : y = "abc\101\102\n\tstu"

o4 = abcAB
stu

o4 : String

We can use peek to see what characters are in the string.

i5 : peek y

o5 = "abcAB\n\tstu"

o5 : String

Another way to enter special characters into strings is to use /// as the string delimiter.

i6 : ///a \ n = "c"///

o6 = a \ n = "c"

o6 : String

The function ascii converts strings to lists of ascii character code, and back again.

i7 : ascii y

o7 = {97, 98, 99, 65, 66, 10, 9, 115, 116, 117}

o7 : List
i8 : ascii oo

o8 = abcAB
stu

o8 : String

We may use the operator | to concatenate strings.

i9 : x|x|x

o9 = abcdefghijabcdefghijabcdefghij

o9 : String

The operator # computes the length of a string.

i10 : #x

o10 = 10

We may also use the operator # to extract single characters from a string. Warning: we number the characters starting with 0.

i11 : x#5

o11 = f

o11 : String

The function substring will extract portions of a string for us.

i12 : substring(x,5)

o12 = fghij

o12 : String
i13 : substring(x,5,2)

o13 = fg

o13 : String

The class of all strings is String.
topindexpreviousupnext