pub fn split_on(string: &str, c: char) -> (&str, Option<&str>)Expand description
A convenience function to split a string on a character.
This is nicer than using string.split(c, 2) because it gives you the two values up-front.
§Returns
A two-tuple of:
- What comes before the split character, or the entire string if there was none; and
- The remainder after the split character, if there was one (even if it’s empty).
assert_eq!(split_on("The quick brown fox", ':'), ("The quick brown fox", None));
assert_eq!(split_on("/", '/'), ("", Some("")));
assert_eq!(split_on("harum = scarum", '='), ("harum ", Some(" scarum")));
assert_eq!(split_on("diæresis:tréma:umlaut", ':'), ("diæresis", Some("tréma:umlaut")));