Logo

Programming-Idioms

  • PHP
  • Rust

Idiom #283 Split with a custom string separator

Build the list parts consisting of substrings of input string s, separated by the string sep.

let parts = s.split(sep);

split returns an iterator.

s may have type &str or String.
let parts: Vec<&str> = s.split(sep).collect();

s may have type &str or String.
let parts = s.split(sep).collect::<Vec<&str>>();

s may have type &str or String.
(def parts (clojure.string/split s sep))

ensure sep is a Regex

New implementation...