basilisp.string

String manipulation utilities.

The functions in this namespace generally are a thin wrapper around Python str methods and may thus generally be assumed to have the same return values as the corresponding methods.

fn (alpha? s)[source]

Return true if s is strictly alphabetic and there is at least one character.

This function uses Python’s underlying str.isalpha() and, thus, it respects unicode.

fn (alphanumeric? s)[source]

Return true if s is strictly alphanumeric and there is at least one character.

This function uses Python’s underlying str.isalnum() and, thus, it respects unicode.

fn (blank? s)[source]

Returns true if s is nil, empty, or contains only whitespace.

fn (capitalize s)[source]

Return a copy of the string s with the first character capitalized and the rest lower case.

fn (digits? s)[source]

Return true if s is strictly digit characters and there is at least one character.

fn (ends-with? s suffix)[source]

Return true if s ends with the substring suffix.

fn (includes? s substr)[source]

Returns true if substr is contained in s.

fn (index-of s value)[source]
fn (index-of s value from-index)

Return the first index of value in s, optionally starting from from-index. Returns nil if value is not found in s.

fn (join coll)[source]
fn (join separator coll)

Return a string of the elements in coll joined together, optionally by a separator.

fn (last-index-of s value)[source]
fn (last-index-of s value from-index)

Return the last index of value in s, optionally searching backwards from from-index. Returns nil if value is not found in s.

fn (lower-case s)[source]

Return a copy of the string s with all characters converted to lower case.

fn (lpad s width)[source]
fn (lpad s width fillchar)

Pad s on the left such that the final string length is width. If the initial string length is less than or equal to width, return the original string. If a fillchar is specified, pad with fillchar. Otherwise, use a space.

fn (ltrim s)[source]

Trim leading whitespace from s.

fn (re-quote-replacement replacement)[source]

Escape special characters in a regex replacement pattern so they are interpreted literally, rather than as special characters.

fn (replace s match replacement)[source]

Replace all instances of match in s with replacement.

match and replacement can be either:

If match is a regex pattern and replacement is a function, that function will be called once for every non-overlapping occurrence of match. The function should accept one string argument and return a replacement string.

If both match and replacement are strings, this function behaves as the Python builtin str.replace().

fn (replace-first s match replacement)[source]

Replace the first instance of match in s with replacement.

match and replacement can be either:

If match is a regex pattern and replacement is a function, that function will be called once for every non-overlapping occurrence of match. The function should accept one string argument and return a replacement string.

If both match and replacement are strings, this function behaves as the Python builtin str.replace() with the count argument set to 1.

fn (reverse s)[source]

Returns a string which is the reverse of s.

fn (rpad s width)[source]
fn (rpad s width fillchar)

Pad s on the right such that the final string length is width. If the initial string length is less than or equal to width, return the original string. If a fillchar is specified, pad with fillchar. Otherwise, use a space.

fn (rtrim s)[source]

Trim trailing whitespace from s.

fn (split s pattern)[source]
fn (split s pattern limit)

Split a string on a regular expression or another string. Caller may optionally limit the maximum number of splits with limit. Returns a vector of the splits.

fn (split-lines s)[source]

Split s on universal newlines as by Python’s str.splitlines().

fn (starts-with? s prefix)[source]

Return true if s starts with the substring prefix.

fn (title-case s)[source]

Return a copy of the string s where the first letter of each word is capitalized and the rest of the characters in the word are lower case.

fn (trim s)[source]

Trim whitespace off the ends of s.

fn (trim-newlines s)[source]

Trim trailing newline and return characters from s.

fn (upper-case s)[source]

Return a copy of the string s with all characters converted to upper case.