Function in string compiler

rfind

fn rfind(string hay, string needle) -> int
Import
use string::{rfind};
Source: compiler/src/builtin_docs/string.hy

Returns the byte offset of the last needle in hay, or -1.

An empty needle matches at hay.len().

Parameters#

NameType
haystring
needlestring

Returns#

int

Examples#

use string::{rfind};
use tests::assert;
assert!(rfind("a/b/c", "/") == 3);
assert!(rfind("abc", "x") == -1);
assert!(rfind("abc", "") == 3);

See also#

  • byte_at: Returns the byte at byte offset i of s, or -1 when i is out of range.
  • find_from: Returns the byte offset of the first needle in hay at or after start, or -1.
  • format: Builds a string from the literal fmt and the arguments that follow it.
  • from_bytes: Decodes bytes as UTF-8 text.
  • match_at: Returns whether needle occurs in s starting exactly at byte offset at.
  • slice_bytes: Returns the part of s between byte offsets start (inclusive) and end (exclusive).
  • to_bytes: Encodes s as UTF-8 into a new Vec<byte>.
↑ ↓ navigate ↵ open