A string is a vector of characters (see Characters). It is generally used for storing and manipulating pieces of text. Librep puts no restrictions on the values which may be stored in a string—specifically, the null character (‘^@’) may be stored with no problems.
In librep, a string is a sequcene of raw bytes, and no encoding is assumed. Some special functions for utf-8 encoded strings are provided. See See utf-8.
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
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).
A newline character.
A carriage return character.
A form feed character.
A TAB character.
A ‘bell’ character (this is Ctrl-g).
A backslash character.
The ‘control’ code of the character c. This is calculated by toggling the seventh bit of the upper-case version of c.
\^C ;A Ctrl-c character (ASCII value 3) \^@ ;The NUL character (ASCII value 0)
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.
The character whose ASCII value is the hexadecimal value ‘12’, i.e. an ‘x’ character followed by one or two hex digits.
If none of the above applies, the leading backslash is ignored. This is sometimes useful for editors syntax parsing, especially for punctuation characters.
This function returns true if its argument is a string.
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 ?$) ⇒ "$$"
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) ⇒ ""
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"
For utf-8 encoded strings, use
This function compares the two strings string1 and string2—if they are made from the same characters in the same order then true is returned.
(string= "one" "one") ⇒ t (string= "one" "two") ⇒ ()
Note that an alternate way to compare strings (or anything!) is to use the
Returns true if string1 and string2 are the same, ignoring differences in character case.
This function returns true if string1 is ‘less’ than
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 Librep the standard
< function understands strings so
string< is just a macro calling that function.
(string< "abc" "abd") ⇒ t (string< "abc" "abb") ⇒ ()
string< but ignores character case in comparisons.
See String Functions for a few more string manipulating functions, and Regular Expressions for a method of pattern matching in strings.