strfind(str: string,pattern: string,): array
Finds all occurrences of a substring within a string.
Returns an array of indices where the search pattern is found within the string. If the pattern's length is greater than the string's length, or if the inputs are invalid, an error is thrown.
Basic usage with multiple occurrences
Basic usage with multiple occurrences
import { assertEquals } from "jsr:@std/assert"; assertEquals(strfind('find indices in the string', 'in'), [1, 5, 13, 23]);
Pattern appears only once
Pattern appears only once
import { assertEquals } from "jsr:@std/assert"; assertEquals(strfind('hello world', 'world'), [6]);
An array of indices where the pattern occurs in the string.