string-util
1 String Utilities
null-string?
default-string
starts-with-char?
ends-with-char?
starts-with?
string-first-char-occurrence
string-common-prefix-length
substring-common-prefix
string-tokenize
weave-string-separator
substring-trim-spaces
7.7

string-util

Raymond Racine <ray.racine@gmail.com>

1 String Utilities

 (require string-util) package: string-util

procedure

(null-string? s)  Boolean

  s : String
(String -> Boolean)

Is the string the empty string?

procedure

(default-string s default)  String

  s : String
  default : String
(-> String String String)

If given string s is the null-string? return the default String, otherwise the String s.

procedure

(starts-with-char? s ch)  Boolean

  s : String
  ch : Char
(String Char -> Boolean)

Does the string start with the char.

procedure

(ends-with-char? s ch)  Boolean

  s : String
  ch : Char
(String Char -> Boolean)

Does the string end with the char.

procedure

(starts-with? s prefix)  Boolean

  s : String
  prefix : String
(String String -> Boolean)

Does the string start with the given prefix.

procedure

(string-first-char-occurrence s ch)  (Option Index)

  s : String
  ch : Char
(String Char -> (Option Index))

Returns the index of the first occurrence of the character in the string scanning from left to right. Returns #f if the character is not found in the string.

procedure

(string-common-prefix-length s1 s2)  Index

  s1 : String
  s2 : String
(String String -> Index)

Given two strings returns the index of their longest common prefix from left to right. In other words, the first index position before the two strings start to diverge.

procedure

(substring-common-prefix s1 s2)  String

  s1 : String
  s2 : String
(String String -> String)

Returns the common prefix string from left to right between two strings.

procedure

(string-tokenize s delims)  (Listof String)

  s : String
  delims : Char-Set
(String Char-Set -> (Listof String))

Split the string into tokens using the set of char delimiters.

procedure

(weave-string-separator sep lst)  String

  sep : String
  lst : (Listof String)
(String (Listof String) -> String)

Weave a the separator string between each string in the list and then reduce to a single string value.

For example:

(weave-string-separator "," '("1" "2" "3"))
"1,2,3"
 
(weave-string-separator "," '("1"))
"1"

procedure

(substring-trim-spaces s start-pos end-pos)  String

  s : String
  start-pos : Integer
  end-pos : Integer
(: substring-trim-spaces (String Integer Integer -> String))

Extracts a substring from the start index inclusive to the end index exclusive. Spaces are trimmed from both ends.