Go to the first, previous, next, last section, table of contents.


Strings

A string is a vector of characters (see section Characters), they are generally used for storing and manipulating pieces of text. Jade puts no restrictions on the values which may be stored in a string -- specifically, the null character (`^@') may be stored with no problems.

The read syntax of a string is a double quote character, followed by the contents of the string, the object is terminated by a second double quote character. For example, "abc" is the read syntax of the string `abc'.

Any backslash characters in the string's read syntax introduce an escape sequence; one or more of the following characters are treated specially to produce the next actual character in the string.

The following escape sequences are supported (all are shown without their leading backslash `\' character).

`n'
A newline character.
`r'
A carriage return character.
`f'
A form feed character.
`t'
A TAB character.
`a'
A `bell' character (this is Ctrl-g).
`^c'
The `control' code of the character c. This is calculated by toggling the seventh bit of the upper-case version of c. For example,
\^C             ;A Ctrl-c character (ASCII value 3)
\^@            ;The NUL character (ASCII value 0)
`012'
The character whose ASCII value is the octal value `012'. After the backslash character the Lisp reader reads up to three octal digits and combines them into one character.
`x12'
The character whose ASCII value is the hexadecimal value `12', i.e. an `x' character followed by one or two hex digits.

Function: stringp object
This function returns t if its argument is a string.

Function: make-string length &optional initial-character
Creates a new string containing length characters, each character is initialised to initial-character (or to spaces if initial-character is not defined).

(make-string 3)
    => "   "

(make-string 2 ?$)
    => "$$"

Function: concat &rest args
This function concatenates all of its arguments, args, into a single string which is returned. If no arguments are given then the null string (`') results.

Each of the args may be a string, a character or a list or vector of characters. Characters are stored in strings modulo 256.

(concat "foo" "bar")
    => "foobar"

(concat "a" ?b)
    => "ab"

(concat "foo" [?b ?a ?r])
    => "foobar"

(concat)
    => ""

Function: substring string start &optional end
This function creates a new string which is a partial copy of the string string. The first character copied is start characters from the beginning of the string. If the end argument is defined it is the index of the character to stop copying at, if it is not defined all characters until the end of the string are copied.

(substring "xxyfoozwx" 3 6)
    => "foo"

(substring "xyzfoobar" 3)
    => "foobar"

Function: string= string1 string2
This function compares the two strings string1 and string2 -- if they are made from the same characters in the same order then t is returned, else nil.

(string= "one" "one")
    => t

(string= "one" "two")
    => nil

Note that an alternate way to compare strings (or anything!) is to use the equal function.

Function: string< string1 string2
This function returns t if string1 is `less' than string2. This is determined by comparing the two strings a character at a time, the first pair of characters which do not match each other are then compared with a normal `less-than' function.

In Jade the standard < function understands strings so string< is just a macro calling that function.

(string< "abc" "abd")
    => t

(string< "abc" "abb")
    => nil

Functions are also available which match regular expressions with strings (see section Searching and Matching Functions) and which apply a mapping to each character in a string (see section Translation Functions).


Go to the first, previous, next, last section, table of contents.