Function in string compiler

find_from

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

Returns the byte offset of the first needle in hay at or after start, or -1.

start is clamped to 0..=hay.len(). An empty needle matches at the clamped start. Offsets are byte offsets.

Parameters#

NameType
haystring
needlestring
startint

Returns#

int

Examples#

use string::{find_from};
use tests::assert;
assert!(find_from("a-b-c", "-", 0) == 1);
assert!(find_from("a-b-c", "-", 2) == 3);
assert!(find_from("a-b-c", "x", 0) == -1);
assert!(find_from("abc", "", 10) == 3);

See also#

  • byte_at: Returns the byte at byte offset i of s, or -1 when i is out of range.
  • 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.
  • rfind: Returns the byte offset of the last needle in hay, or -1.
  • 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