core.str

Source code: core/str.seq

extension str

Magic methods:

__init__()
__hash__()
__eq__(other: str)
__ne__(other: str)
__lt__(other: str)
__le__(other: str)
__gt__(other: str)
__ge__(other: str)
__str__()
__repr__()
__len__()
__bool__()
__add__(other: str)
__getitem__(idx: int)
__getitem__(s: eslice)
__getitem__(s: slice)
__getitem__(s: lslice)
__getitem__(s: rslice)
__getitem__(s: esslice)
__getitem__(s: rsslice)
__getitem__(s: lsslice)
__getitem__(s: sslice)
__contains__(pattern: str)
__iter__()
__reversed__()
__mul__(x: int)
__copy__()

Methods:

c_str()
cat(v: list[str])
cati(v: generator[str], total: int)
cati_ext(v: generator[str])
join(l)
from_ptr(t: cobj)
isdigit()

str.isdigit() -> bool

Return True if all characters in str are digits and there is at least one character in str, False otherwise.

islower()

str.islower() -> bool

Return True if all cased characters in str are lowercase and there is at least one cased character in str, False otherwise.

isupper()

str.isupper() -> bool

Return True if all cased characters in str are uppercase and there is at least one cased character in str, False otherwise.

isalnum()

str.isalnum() -> bool

Return True if all characters in str are alphanumeric and there is at least one character in str, False otherwise.

isalpha()

str.isalpha() -> bool

Return True if all characters in str are alphabetic and there is at least one character in str, False otherwise.

isspace()

str.isspace() -> bool

Return True if all characters in str are whitespace and there is at least one character in str, False otherwise.

istitle()

str.istitle() -> bool

Return True if str is a titlecased string and there is at least one character in str, i.e. uppercase characters may only follow uncased characters and lowercase characters only cased ones. Return False otherwise.

capitalize()

str.capitalize() -> copy of str

Return a copy of str with only its first character capitalized (ASCII) and the rest lower-cased.

isdecimal()

str.isdecimal() -> bool

Return True if str is a decimal string, False otherwise. str is a decimal string if all characters in str are decimal and there is at least one character in str.

lower()

str.lower() -> copy of str

Return a copy of str with all ASCII characters converted to lowercase.

upper()

str.upper() -> copy of str

Return a copy of str with all ASCII characters converted to uppercase.

isascii()

str.isascii() -> bool

Return True if str is empty or all characters in str are ASCII, False otherwise.

casefold()

str.casefold() -> copy of str

Return a version of the string suitable for caseless comparisons.

Unlike Python, casefold() deals with just ASCII characters.

swapcase()

str.swapcase() -> copy of str

Return a copy of str with uppercase ASCII characters converted to lowercase ASCII and vice versa.

title()

str.title() -> copy of str

Return a titlecased version of str, i.e. ASCII words start with uppercase characters, all remaining cased characters have lowercase.

isnumeric()

str.isdecimal() -> bool

Return True if the string is a numeric string, False otherwise. A string is numeric if all characters in the string are numeric and there is at least one character in the string.

Unlike Python, isnumeric() deals with just ASCII characters.

ljust(width: int, fillchar: str)

ljust(width[, fillchar]) -> string

Return a left-justified string of length width.

Padding is done using the specified fill character (default is a space).

rjust(width: int, fillchar: str)

rjust(width[, fillchar]) -> string

Return a right-justified string of length width.

Padding is done using the specified fill character (default is a space).

center(width: int, fillchar: str)

str.center(width[, fillchar]) -> string

Return str centered in a string of length width. Padding is done using the specified fill character (default is a space)

zfill(width: int)

str.zfill(width) -> string

Pad a numeric string str with zeros on the left, to fill a field of the specified width. The string str is never truncated.

count(sub: str, start: int = 0, end: int = 0x7fffffffffffffff)

str.count(sub[, start[, end]]) -> int

Return the number of occurrences of subsection sub in bytes str[start:end]. Optional arguments start and end are interpreted as in slice notation.

find(sub: str, start: int = 0, end: int = 0x7fffffffffffffff)

str.find(sub [,start [,end]]) -> int

Return the lowest index in str where substring sub is found, such that sub is contained within str[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

rfind(sub: str, start: int = 0, end: int = 0x7fffffffffffffff)

str.rfind(sub [,start [,end]]) -> int

Return the highest index in str where substring sub is found, such that sub is contained within str[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

isidentifier()

str.isidentifier() -> bool

Return True if the string is a valid identifier, False otherwise. Unlike Python, isidentifier() deals with just ASCII characters.

isprintable()

str.isprintable() -> bool

Return True if the string is printable or empty, False otherwise. Unlike Python, isprintable() deals with just ASCII characters.

lstrip(chars: str = '')

str.lstrip([chars]) -> string

Return a copy of the string str with leading whitespace removed. If chars is given, remove characters in chars instead. Unlike Python, lstrip() deals with just ASCII characters.

rstrip(chars: str = '')

str.rstrip([chars]) -> string

Return a copy of the string str with trailing whitespace removed. If chars is given, remove characters in chars instead. Unlike Python, lstrip() deals with just ASCII characters.

strip(chars: str = '')

str.strip([chars]) -> string

Return a copy of the string str with leading and trailing whitespace removed. If chars is given, remove characters in chars instead. Unlike Python, lstrip() deals with just ASCII characters.

partition(sep: str)

Search for the separator sep in str, and return the part before it, the separator itself, and the part after it. If the separator is not found, return str and two empty strings.

rpartition(sep: str)

Search for the separator sep in str, starting at the end of str, and return the part before it, the separator itself, and the part after it. If the separator is not found, return two empty strings and str.

split(sep: optional[str] = None, maxsplit: int = - 1)

str.split([sep [,maxsplit]]) -> list of strings

Return a list of the words in the string str, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified, any whitespace string is a separator and empty strings are removed from the result.

rsplit(sep: optional[str] = None, maxsplit: int = - 1)

str.rsplit([sep [,maxsplit]]) -> list of strings

Return a list of the words in the string str, using sep as the delimiter string, starting at the end of the string and working to the front. If maxsplit is given, at most maxsplit splits are done. If sep is not specified, any whitespace string is a separator.

splitlines(keepends: bool = False)

str.splitlines([keepends]) -> list of strings

Return a list of the lines in str, breaking at line boundaries. Line breaks are not included in the resulting list unless keepends is given and true.

startswith(prefix: str, start: int = 0, end: int = 0x7fffffffffffffff)

str.startswith(prefix[, start[, end]]) -> bool

Return True if str starts with the specified prefix, False otherwise. With optional start, test str beginning at that position. With optional end, stop comparing str at that position.

endswith(suffix: str, start: int = 0, end: int = 0x7fffffffffffffff)

str.endswith(prefix[, start[, end]]) -> bool

Return True if str ends with the specified suffix, False otherwise. With optional start, test str beginning at that position. With optional end, stop comparing str at that position.

index(sub: str, start: int = 0, end: int = 0x7fffffffffffffff)

str.index(sub [,start [,end]]) -> int

Like str.find() but raise ValueError when the substring is not found.

rindex(sub: str, start: int = 0, end: int = 0x7fffffffffffffff)

str.index(sub [,start [,end]]) -> int

Like str.find() but raise ValueError when the substring is not found.

replace(old: str, new: str, maxcount: int = - 1)

str.replace(old, new[, count]) -> string

Return a copy of string str with all occurrences of substring old replaced by new. If the optional argument maxcount is given, only the first maxcount occurrences are replaced.

For now, maxcount is required.

expandtabs(tabsize: int = 8)

str.expandtabs([tabsize]) -> string

Return a copy of str where all tab characters are expanded using spaces. If tabsize is not given, a tab size of 8 characters is assumed.

translate(table)

Return a copy with each character mapped by the given translation table.

Unlike Python, translate() currently does not allow the translation table to be a bytes object of length 256.

As well, None implemented yet until None and be placed inside the table with other strings. Use: {‘a’: ‘’} to replace a string for now