find_all_exact

Function find_all_exact 

Source
pub fn find_all_exact<B, S>(base: &B, find: &S) -> Vec<(usize, usize)>
where B: ToString, S: ToString,
Expand description

§Description

Finds all sub-string occurrences and ranges the sub-strings occur at. All provided arguments are assumed to be valid UTF-8 chars.

§Arguments

  • base - The base string we are searching.
  • find - The sub-string we are trying to find all occurrences of.

§Output

  • Vec<(usize, usize)> - A vector of tuples containing 2 usize numbers. The first number is the starting position of the occurrence, the second number is where the occurrence ends. The vector will be empty if no occurrences were found.

§Examples

use string_simple::compare::find_all_exact;

let base_string = String::from("This is my test string! test test!");
let find_string = String::from("test");

// output in this case will look like this: [(11, 15), (24, 28), (29, 33)]
let result = find_all_exact(&base_string, &find_string);