Summary#
Text.LastIndexOf(s, sub) returns the zero-based index of the last ordinal occurrence of sub in
s, or -1 when sub does not occur — exactly C#'s string.LastIndexOf. The 3-arg overload
Text.LastIndexOf(s, sub, startIndex) begins the search at startIndex and proceeds backward toward
the beginning, matching C#'s LastIndexOf(value, startIndex).
Signature#
Text.LastIndexOf(<string> s, <string> sub) -> int
Text.LastIndexOf(<string> s, <string> sub, <int> startIndex) -> intDescription#
Matching is ordinal (byte-for-byte, culture-independent), the same as its forward-search sibling
Text.IndexOf. A miss returns -1.
⚠ For word-boundary truncation, reach for Text.Truncate instead. It is the same idea done
once and correctly — it bounds the result by the budget including the ellipsis, handles a single long
word and a leading space, and trims the trailing space. Hand-rolled versions of it (including the Clip
below) routinely overshoot the budget they were given. Use Text.LastIndexOf directly when you want the
INDEX for something else.
Text.LastIndexOf is in-memory only — like Text.Reverse, it has no faithful SQL form, so it may be
called on locals inside a function body but not pushed down into a query predicate.
The 3-arg startIndex is the C# contract: it is the last position considered, and the search runs
backward. As in C#, an out-of-range startIndex faults rather than clamping.
Examples#
string Clip(string content, int budget) {
var cut = Text.LastIndexOf(content, " ", budget); // last space at/before the budget
if (cut < 0) {
return content; // no space → keep whole
}
return Text.Substring(content, 0, cut);
}
// Clip("the quick brown fox", 12) -> "the quick"See also#
- Text.IndexOf — the forward-search sibling, with the same
startIndexcontract