Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Rust split string by nothing

In js I would do this

"abc".split("") // ["a","b","c"]

I want something simlimar in rust

let splits = String::from("abc").split("") // does not work with empty string!!! 
let letters = (
  splits.next().unwrap(),
  splits.next().unwrap(),
  splits.next().unwrap(),
) // ('a','b','c') 

I want something simlimar in rust but it does not work. no error no nothing

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could use this:

let s = String::from("abc");
let mut chars = s.chars();

let letters = (
    chars.next().unwrap(),
    chars.next().unwrap(),
    chars.next().unwrap(),
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading