[next][up][top][index]
search for:

strings -- an overview

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

i1 : "abcdefghij"

o1 = abcdefghij

Strings may contain newline characters.

i2 : "abcde
     fghij"

o2 = abcde
     fghij

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

i3 : x = "abcdefghij"

o3 = abcdefghij

There are escape sequences that 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

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

i5 : peek y

o5 = "abcAB\n\tstu"

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

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

o6 = a \ n = "c"

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

We may use the operator | to concatenate strings.

i9 : x|x|x

o9 = abcdefghijabcdefghijabcdefghij

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

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

i12 : substring(x,5)

o12 = fghij
i13 : substring(x,5,2)

o13 = fg

The class of all strings is String.


[next][up][top][index]
search for: