String library of the Chaos language. You can install this spell with:
occultist install string
and import it with:
import string
Makes the all characters in string s
uppercase.
kaos> string.upper("hello world")
HELLO WORLD
Makes the all characters in string s
lowercase.
kaos> import string
kaos> string.lower("HeLlO WoRLd")
hello world
Capitalizes the string s
.
kaos> string.capitalize("hello world")
Hello world
Concatenates string s1
and string s2
.
kaos> string.concat("hello", " world")
hello world
Splits the string s
into a list according to the string delimiter
.
kaos> string.split("A quick brown fox jumps over the lazy dog", " ")
['A', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']
Concatenates a list of strings words
into a string by separating them with string separator
.
kaos> list a = ["foo", "bar", "baz"]
kaos> string.join(a, " ")
foo bar baz
kaos> string.join(a, "")
foobarbaz
Finds the position of the first occurrence of substring needle
in string haystack
if successful. Returns -1
if unsuccessful.
kaos> string.search("hello world", "world")
6
kaos> string.search("hello world", "friend")
-1
Replaces all occurrences of the needle
string with the replacement
string.
kaos> string.replace("hello world", "world", "friend")
hello friend
Returns the length of the string s
.
kaos> string.length("hello world")
11
Returns whether the string s
empty or not.
kaos> string.is_empty("hello world")
false
kaos> string.is_empty("")
true
Returns true
if all characters in the string s
are numeric characters, and there is at least one character, false
otherwise.
kaos> string.is_numeric("01234")
true
kaos> string.is_numeric("01234x")
false
kaos> string.is_numeric(" 01234")
false
kaos> string.is_numeric(" ")
false
kaos> string.is_numeric("")
false
Returns true
if string s
only contains alphabetic characters or whitespace and not empty, false
otherwise.
kaos> string.is_alpha("hello world")
true
kaos> string.is_alpha("he11o w0rld")
false
kaos> string.is_alpha(" ")
true
kaos> string.is_alpha("")
false
Returns true
if string s
only contains alphanumeric characters or whitespace and not empty, false
otherwise.
kaos> string.is_alnum("he11o w0rld")
true
kaos> string.is_alnum(" ")
true
kaos> string.is_alnum("")
false
Returns true
if string s
only contains whitespaces and not empty, false
otherwise.
kaos> string.is_space("he11o w0rld\t")
false
kaos> string.is_space("a")
false
kaos> string.is_space("1")
false
kaos> string.is_space("\n")
true
kaos> string.is_space(" ")
true
kaos> string.is_space("")
false
Returns true
if string s
only contains lowercase alphabetic characters, numeric characters or whitespace, false
otherwise.
kaos> string.is_lower("hello world")
true
kaos> string.is_lower("hello world 01234")
true
kaos> string.is_lower("HELLO WORLD")
false
kaos> string.is_lower("HeLlO WoRLd")
false
kaos> string.is_lower(" ")
true
kaos> string.is_lower("")
false
Returns true
if string s
only contains uppercase alphabetic characters, numeric characters or whitespace, false
otherwise.
kaos> string.is_upper("hello world")
false
kaos> string.is_upper("HELLO WORLD")
true
kaos> string.is_upper("HELLO WORLD 01234")
true
kaos> string.is_upper("HeLlO WoRLd")
false
kaos> string.is_upper(" ")
true
kaos> string.is_upper("")
false
Returns the string that contains whitespace characters \t\n\r\v\f
.
kaos> string.whitespace()
\t\n\r\v\f
Returns the string that contains ASCII lowercase letters abcdefghijklmnopqrstuvwxyz
.
kaos> string.ascii_lowercase()
abcdefghijklmnopqrstuvwxyz
Returns the string that contains ASCII uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ
.
kaos> string.ascii_uppercase()
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Returns the string that contains ASCII letters abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
.
kaos> string.ascii_letters()
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
Returns the string that contains decimal digits 0123456789
.
kaos> string.digits()
0123456789
Returns the string that contains hexadecimal digits 0123456789abcdefABCDEF
.
kaos> string.hexdigits()
0123456789abcdefABCDEF
Returns the string that contains octal digits 0123456789
.
kaos> string.octdigits()
01234567
Returns the characters considered punctuation according to ASCII !"#$%&'()*+,-./:;<=>?@[\]^_
{|}~`
kaos> string.punctuation()
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~