Next: String Modification, Previous: List/String Conversion, Up: Strings
Portions of strings can be extracted by these procedures.
string-ref delivers individual characters whereas
substring can be used to extract substrings from longer strings.
Return the number of characters in string.
Return the number of characters in str as a
size_t.
Return character k of str using zero-origin indexing. k must be a valid index of str.
Return character k of str using zero-origin indexing. k must be a valid index of str.
Return a copy of the given string str.
The returned string shares storage with str initially, but it is copied as soon as one of the two strings is modified.
Return a new string formed from the characters of str beginning with index start (inclusive) and ending with index end (exclusive). str must be a string, start and end must be exact integers satisfying:
0 <= start <= end <=
(string-lengthstr).The returned string shares storage with str initially, but it is copied as soon as one of the two strings is modified.
Like
substring, but the strings continue to share their storage even if they are modified. Thus, modifications to str show up in the new string, and vice versa.
Like
substring, but the storage for the new string is copied immediately.
Like
substring, but the resulting string can not be modified.
Like
scm_substring, etc. but the bounds are given as asize_t.
Return the n first characters of s.
Return all but the first n characters of s.
Return the n last characters of s.
Return all but the last n characters of s.
Take characters start to end from the string s and either pad with char or truncate them to give len characters.
string-padpads or truncates on the left, so for example(string-pad "x" 3) => " x" (string-pad "abcde" 3) => "cde"
string-pad-rightpads or truncates on the right, so for example(string-pad-right "x" 3) => "x " (string-pad-right "abcde" 3) => "abc"
Trim occurrances of char_pred from the ends of s.
string-trimtrims char_pred characters from the left (start) of the string,string-trim-righttrims them from the right (end) of the string,string-trim-bothtrims from both ends.char_pred can be a character, a character set, or a predicate procedure to call on each character. If char_pred is not given the default is whitespace as per
char-set:whitespace(see Standard Character Sets).(string-trim " x ") => "x " (string-trim-right "banana" #\a) => "banan" (string-trim-both ".,xy:;" char-set:punctuation) => "xy" (string-trim-both "xyzzy" (lambda (c) (or (eqv? c #\x) (eqv? c #\y)))) => "zz"