std-method

str::find

Locate the first match and return its starting byte offset. None means no match; the offset may differ from its scalar position. Expected stdout (not executed): Some(2) Common mistake: Using the returned byte offset as a scalar index.

Formal Syntax & Structure

rust syntaxrust
fn find<P: Pattern>(&self, pat: P) -> Option<usize>

Working Example

Example Snippetrust
fn main() {    let text = "ش:42";    println!("{:?}", text.find(':'));}
Rust Reference