1. Module (chicken string)
    1. conc
    2. ->string
    3. string-chop
    4. string-chomp
    5. string-compare3
    6. string-intersperse
    7. string-split
    8. string-translate
    9. string-translate*
    10. substring=?
    11. substring-index
    12. reverse-list->string
    13. reverse-string-append

Module (chicken string)

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


[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)) )


[procedure] (->string X)

Returns a string-representation of X.


[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")


[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".


[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.


[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"))


[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")


[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.


[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:

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


[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).


[procedure] (substring-index WHICH WHERE [START])
[procedure] (substring-index-ci WHICH WHERE [START])

Searches for first index in string WHERE where string WHICH 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.


[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.


[procedure] (reverse-string-append LIST)

(apply string-append (reverse LIST))

Previous: Module (chicken sort)

Next: Module (chicken syntax)