src/pylib/pystring/strmeth

Search:
Group by:
Source   Edit  

Procs

func capitalize(a: PyStr): PyStr {....raises: [], tags: [], forbids: [].}

make the first character have title/upper case and the rest lower case.

changed when Python 3.8: the first character will have title case.

while Nim's unicode.capitalize only make the first character upper-case.

Source   Edit  
func casefold(a: PyStr): PyStr {....raises: [], tags: [], forbids: [].}
Admonition: since Python 3.3

str.casefold()

str.lower() is used for most characters, but, for example, Cherokee letters is casefolded to their uppercase counterparts, and some will be converted to their normal case, e.g. "ß" -> "ss"

Source   Edit  
func center(a: PyStr; width: int; fillchar = ' '): PyStr {....raises: [], tags: [],
    forbids: [].}
Mimics Python str.center(width: int, fillchar: str=" ") -> str Source   Edit  
func center(a: PyStr; width: int; fillchar: PyStr): PyStr {....raises: [TypeError],
    tags: [], forbids: [].}
Source   Edit  
func count(a: PyStr; sub: PyStr): int {....raises: [], tags: [], forbids: [].}
Source   Edit  
func count(a: PyStr; sub: PyStr; start = 0; end: int): int {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
func count(a: PyStr; sub: PyStr; start: int): int {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func endsWith(a: char; suffix: PyStr): bool {....raises: [], tags: [], forbids: [].}
Source   Edit  
func endsWith(a: PyStr; suffix: char): bool {....raises: [], tags: [], forbids: [].}
Source   Edit  
func endsWith[Suf: PyStr | tuple](a: PyStr; suffix: Suf; start, end: int): bool
Source   Edit  
func endsWith[Suf: PyStr | tuple](a: PyStr; suffix: Suf; start: int): bool
Source   Edit  
func endsWith[Tup: tuple](a: PyStr; suffix: Tup): bool
Source   Edit  
func expandtabs(a: PyStr; tabsize = 8): PyStr {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func find(a: PyStr; b: PyStr; start = 0; end = len(a)): int {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
func index(a, b: PyStr; start = 0; end = len(a)): int {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
Source   Edit  
func isalpha(a: PyStr): bool {....raises: [], tags: [], forbids: [].}
Source   Edit  
func isascii(a: PyStr): bool {....raises: [], tags: [], forbids: [].}
Admonition: since Python 3.7
Source   Edit  
func isascii(a: Rune): bool {....raises: [], tags: [], forbids: [].}
Source   Edit  
func islower(a: PyStr): bool {....raises: [], tags: [], forbids: [].}
Source   Edit  
func isspace(a: PyStr): bool {....raises: [], tags: [], forbids: [].}
Source   Edit  
func istitle(a: PyStr): bool {....raises: [], tags: [], forbids: [].}
Source   Edit  
func isupper(a: PyStr): bool {....raises: [], tags: [], forbids: [].}
Source   Edit  
func join[T](sep: PyStr; a: openArray[T]): PyStr
Mimics Python join() -> string Source   Edit  
func ljust(a: PyStr; width: int; fillchar = ' '): PyStr {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func ljust(a: PyStr; width: int; fillchar: PyStr): PyStr {....raises: [TypeError],
    tags: [], forbids: [].}
Source   Edit  
func lower(a: PyStr): PyStr {....raises: [], tags: [], forbids: [].}

str.lower

not the same as Nim's unicode.toLower, see examples

Example:

import std/unicode
let dotI = Rune 0x0130  # Δ°  (LATIN CAPITAL LETTER I WITH DOT ABOVE)
assert str(dotI).lower() == "i\u0307"  ## i̇ (\u0207 is a upper dot)
assert dotI.toLower() == Rune('i')
Source   Edit  
func partition(a: PyStr; sep: PyStr): tuple[before, sep, after: PyStr] {.
    ...raises: [ValueError], tags: [], forbids: [].}
Source   Edit  
func removeprefix(a: PyStr; suffix: PyStr): PyStr {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func removesuffix(a: PyStr; suffix: PyStr): PyStr {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func replace(a: PyStr; sub, by: PyStr | char): PyStr
Source   Edit  
func replace(a: PyStr; sub, by: PyStr | char; count: int): PyStr

str.replace(sub, by, count = -1)

count may be negative or zero.

Source   Edit  
func rfind(a: PyStr; b: PyStr; start = 0; end = len(a)): int {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
func rindex(a, b: PyStr; start = 0; end = len(a)): int {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
Source   Edit  
func rjust(a: PyStr; width: int; fillchar = ' '): PyStr {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func rjust(a: PyStr; width: int; fillchar: PyStr): PyStr {....raises: [TypeError],
    tags: [], forbids: [].}
Source   Edit  
func rpartition(a: PyStr; sep: PyStr): tuple[before, sep, after: PyStr] {.
    ...raises: [ValueError], tags: [], forbids: [].}
Source   Edit  
func startsWith(a: char; suffix: PyStr): bool {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func startsWith(a: PyStr; suffix: char): bool {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func startsWith[Suf: PyStr | tuple](a: PyStr; suffix: Suf; start, end: int): bool
Source   Edit  
func startsWith[Suf: PyStr | tuple](a: PyStr; suffix: Suf; start: int): bool
Source   Edit  
func startsWith[Tup: tuple](a: PyStr; suffix: Tup): bool
Source   Edit  
func title(a: PyStr): PyStr {....raises: [], tags: [], forbids: [].}

str.title()

not the same as title proc in std/unicode, see example.

Example:

let s = "Η‰"  # \u01c9
let u = str(s)
assert u.title() == "Lj"  # \u01c8
import std/unicode
assert unicode.title(s) == "Η‡"  # \u01c7
Source   Edit  
func upper(a: PyStr): PyStr {....raises: [], tags: [], forbids: [].}

str.upper

not the same as Nim's unicode.toUpper, see examples

Example:

import std/unicode
let a = "αΎ·"
# GREEK SMALL LETTER ALPHA WITH PERISPOMENI AND YPOGEGRAMMENI
assert str(a).upper() == "Ξ‘Ν‚Ξ™"  # 3 chars
assert a.toUpper() == a   # Nim just maps it as-is.
# There is more examples... (101 characters in total)
Source   Edit  
func zfill(a: PyStr; width: int): PyStr {....raises: [], tags: [], forbids: [].}
Source   Edit  

Templates

template `*`(a: StringLike; i: int): PyStr
Source   Edit  
template `*`(i: int; a: StringLike): PyStr
Source   Edit