SHARE
TWEET

Untitled

a guest Apr 26th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pub fn substr(s: &String, target: &str) -> bool {
  2.     let l1 = s.len(); //length of main string
  3.     let l2 = target.len(); //length of substring
  4.    
  5.     if target == "" { return true } // base case
  6.    
  7.     for i in 0..(l1 - l2 + 1) {
  8.         let mut j = 0;
  9.         for k in 0..l2 {
  10.             j = k;
  11.             println!("comparing {} with {}", s.chars().skip(i + j).next().unwrap(), target.chars().skip(j).next().unwrap());
  12.             if s.chars().skip(i + j).next().unwrap() != target.chars().skip(j).next().unwrap() {
  13.                 break
  14.             }
  15.         }
  16.         println!("stopping, i = {}, j = {}, l2 = {}", i, j, l2);
  17.         if (j + 1) == l2 { return true }
  18.     }
  19.     false
  20. }
  21.  
  22. fn main() {
  23.     println!("{}", substr(&"rustacean".to_string(), &"acean"));
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top