How to count the number of non-overlapping instances of substring in a string in Rust

1 Answer

0 votes
fn main() {
    let s = "rust java php c++ python php phphp";
    
    let count = s.matches("php").count();
    
    println!("{}", count);
}

 
 
/*
run:

3

*/

 



answered Aug 24, 2024 by avibootz
...