1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/// Contain string /// /// Find the first occurrence of needle in haystack. /// /// # Examples /// /// Basic usage: /// ``` /// let result = algorithmz::string::contain_string("hello", "ll"); /// assert_eq!(result, true); /// ``` pub fn contain_string(haystack: &str, needle: &str) -> bool { if needle.is_empty() { return false; } if needle.len() > haystack.len() { return false; } for i in 0..haystack.len() { if haystack.len() - i < needle.len() { return false; } if &haystack[i..i + needle.len()] == needle { return true; } } false }