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
trueifsis 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
trueifsis strictly alphanumeric and there is at least one character.This function uses Python’s underlying
str.isalnum()and, thus, it respects unicode.
- fn (capitalize s)[source]¶
Return a copy of the string
swith the first character capitalized and the rest lower case.
- fn (digits? s)[source]¶
Return
trueifsis strictly digit characters and there is at least one character.
- fn (index-of s value)[source]¶
- fn (index-of s value from-index)
Return the first index of value in
s, optionally starting fromfrom-index. Returnsnilif value is not found ins.
- fn (join coll)[source]¶
- fn (join separator coll)
Return a string of the elements in
colljoined together, optionally by aseparator.
- 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 fromfrom-index. Returnsnilif value is not found ins.
- fn (lower-case s)[source]¶
Return a copy of the string
swith all characters converted to lower case.
- fn (lpad s width)[source]¶
- fn (lpad s width fillchar)
Pad
son the left such that the final string length iswidth. If the initial string length is less than or equal towidth, return the original string. If afillcharis specified, pad withfillchar. Otherwise, use a space.
- 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
swithreplacement.matchandreplacementcan be either:re.Patternand (stror a function)
If
matchis a regex pattern andreplacementis 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
matchandreplacementare strings, this function behaves as the Python builtinstr.replace().
- fn (replace-first s match replacement)[source]¶
Replace the first instance of match in
swithreplacement.matchandreplacementcan be either:re.Patternand (stror a function)
If
matchis a regex pattern andreplacementis 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
matchandreplacementare strings, this function behaves as the Python builtinstr.replace()with thecountargument set to 1.
- fn (rpad s width)[source]¶
- fn (rpad s width fillchar)
Pad
son the right such that the final string length iswidth. If the initial string length is less than or equal towidth, return the original string. If afillcharis specified, pad withfillchar. Otherwise, use a space.
- 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
son universal newlines as by Python’sstr.splitlines().