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
ifs
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
ifs
is 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
s
with the first character capitalized and the rest lower case.
- fn (digits? s)[source]¶
Return
true
ifs
is 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
. Returnsnil
if value is not found ins
.
- fn (join coll)[source]¶
- fn (join separator coll)
Return a string of the elements in
coll
joined 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
. Returnsnil
if value is not found ins
.
- 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 iswidth
. If the initial string length is less than or equal towidth
, return the original string. If afillchar
is 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
s
withreplacement
.match
andreplacement
can be either:re.Pattern
and (str
or a function)
If
match
is a regex pattern andreplacement
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
andreplacement
are strings, this function behaves as the Python builtinstr.replace()
.
- fn (replace-first s match replacement)[source]¶
Replace the first instance of match in
s
withreplacement
.match
andreplacement
can be either:re.Pattern
and (str
or a function)
If
match
is a regex pattern andreplacement
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
andreplacement
are strings, this function behaves as the Python builtinstr.replace()
with thecount
argument set to 1.
- fn (rpad s width)[source]¶
- fn (rpad s width fillchar)
Pad
s
on 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 afillchar
is 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
s
on universal newlines as by Python’sstr.splitlines()
.