home ~ projects ~ socials

Split A Rust String Into Individual Characters

Chop Chop

The .split() on a String outputs empty strings at the start and end. This is how I'm removing them.

fn main() {
  let input = "abdef".to_string();
  let splitted = input
    .split("")
    .skip(1)
    .take(input.len())
    .collect::<Vec<&str>>();
  dbg!(splitted);

}
Output:
[_active_nvim_run:8:3] splitted = [
    "a",
    "b",
    "d",
    "e",
    "f",
]
-- end of line --