Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Text search

All these methods observe their strings once in source order, accept references, and allocate nothing. Matches are literal UTF-8, with no normalization, case folding, or regex interpretation. Optional bounds are unsupported.

OperationResultBehavior
text.startswith(prefix)boolExact prefix; empty prefix always matches
text.endswith(suffix)boolExact suffix; empty suffix always matches
text.find(needle)Option[i64]First matching scalar position, or Nothing
text.rfind(needle)Option[i64]Last matching scalar position, or Nothing
text.count(needle)i64Number of non-overlapping matches, left to right

Each method takes exactly one string argument. Prefix and suffix checks do not accept tuples of alternatives. An empty needle matches at zero for find, at len(text) for rfind, and at all len(text) + 1 scalar boundaries for count. The last rfind match can overlap an earlier match. Converting a found byte position to a scalar position scans the preceding prefix.

needle in text and needle not in text provide substring membership. A substring view &s[a:b] supports in, startswith, endswith, and find, with a str or &substr argument.