Created
June 15, 2021 03:06
-
-
Save orez-/11a176393d4baa695706c7a6b41e5c39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn partition<'a>(s: &'a str, p: &str) -> (&'a str, &'a str) { | |
match s.find(p) { | |
Some(i) => (&s[..i], &s[i+p.len()..]), | |
None => (s, ""), | |
} | |
} | |
fn rpartition<'a>(s: &'a str, p: &str) -> (&'a str, &'a str) { | |
match s.rfind(p) { | |
Some(i) => (&s[..i], &s[i+p.len()..]), | |
None => ("", s), | |
} | |
} | |
fn main() { | |
println!("{:?}", partition("wowie zowie kablowie", " ")); | |
println!("{:?}", partition("single", " ")); | |
println!("{:?}", rpartition("wowie zowie kablowie", " ")); | |
println!("{:?}", rpartition("single", " ")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment