Garden 🌻

String::split_once

Split this string on the first occurrence of needle, and return the text before and after needle.

"abcd".split_once("b") //-> Some(["a", "cd"])
Source Codepublic method split_once(this: String, needle: String): Option<(String, String)> {
  match this.index_of(needle) {
    None => None
    Some(i) => {
      Some((
        this.substring(0, i),
        this.substring(i + needle.len(), this.len()),
      ))
    }
  }
}