You are looking at historical revision 38853 of this page. It may differ significantly from its current revision.

Module (chicken string)

This module contains procedures which can perform various useful string operations.

conc

[procedure] (conc X ...)

Returns a string with the string-represenation of all arguments concatenated together. conc could be implemented as

(define (conc . args)
  (apply string-append (map ->string args)) )

->string

[procedure] (->string X)

Returns a string-representation of X.

string-chop

[procedure] (string-chop STRING LENGTH)

Returns a list of substrings taken by chopping STRING every LENGTH characters:

(string-chop "one two three" 4)  ==>  ("one " "two " "thre" "e")

string-chomp

[procedure] (string-chomp STRING [SUFFIX])

If STRING ends with SUFFIX, then this procedure returns a copy of its first argument with the suffix removed, otherwise returns STRING unchanged. SUFFIX defaults to "\n".

string-compare3

[procedure] (string-compare3 STRING1 STRING2)
[procedure] (string-compare3-ci STRING1 STRING2)

Perform a three-way comparison between the STRING1 and STRING2, returning either -1 if STRING1 is lexicographically less than STRING2, 0 if it is equal, or 1 if it s greater. string-compare3-ci performs a case-insensitive comparison.

string-intersperse

[procedure] (string-intersperse LIST [STRING])

Returns a string that contains all strings in LIST concatenated together. STRING is placed between each concatenated string and defaults to " ".

(string-intersperse '("one" "two") "three")

is equivalent to

(apply string-append (intersperse '("one" "two") "three"))

string-split

[procedure] (string-split STRING [DELIMITER-STRING [KEEPEMPTY]])

Split string into substrings delimited by any of the characters given in the delimiter string. If no delimiters are specified, a string comprising the tab, newline and space characters is assumed. If the parameter KEEPEMPTY is given and not #f, then empty substrings are retained:

(string-split "one  two  three") ==> ("one" "two" "three")
(string-split "foo:bar::baz:" ":" #t) ==> ("foo" "bar" "" "baz" "")
(string-split "foo:bar:baz,quux,zot" ":," ) ==> ("foo" "bar" "baz" "quux" "zot")

string-translate

[procedure] (string-translate STRING FROM [TO])

Returns a fresh copy of STRING with characters matching FROM translated to TO. If TO is omitted, then matching characters are removed. FROM and TO may be a character, a string or a list. If both FROM and TO are strings, then the character at the same position in TO as the matching character in FROM is substituted.

string-translate*

[procedure] (string-translate* STRING SMAP)

Substitutes elements of STRING according to SMAP. SMAP should be an association-list where each element of the list is a pair of the form (MATCH . REPLACEMENT). Every occurrence of the string MATCH in STRING will be replaced by the string REPLACEMENT:

(string-translate*
  "<h1>this is a \"string\"</h1>"
  '(("<" . "&lt;") (">" . "&gt;") ("\"" . "&quot;")) )
=>  "&lt;h1&gt;this is a &quot;string&quot;&lt;/h1&gt;"

substring=?

[procedure] (substring=? STRING1 STRING2 [START1 [START2 [LENGTH]]])
[procedure] (substring-ci=? STRING1 STRING2 [START1 [START2 [LENGTH]]])

Returns #t if the strings STRING1 and STRING2 are equal, or #f otherwise. The comparison starts at the positions START1 and START2 (which default to 0), comparing LENGTH characters (which defaults to the minimum of the remaining length of both strings).

substring-index

[procedure] (substring-index MAYBE-SUBSTRING STRING [START])
[procedure] (substring-index-ci MAYBE-SUBSTRING STRING [START])

Searches for first index in string STRING where string MAYBE-SUBSTRING occurs. If the optional argument START is given, then the search starts at that index. substring-index-ci is a case-insensitive version of substring-index.

reverse-list->string

[procedure] (reverse-list->string LIST)

Returns a string with the characters in LIST in reverse order. This is equivalent to (list->string (reverse LIST)), but much more efficient.

reverse-string-append

[procedure] (reverse-string-append LIST)

(apply string-append (reverse LIST))


Previous: Module (chicken sort)

Next: Module (chicken syntax)