Converting a string to vectors and back

How to convert a String to a vector of chars?

1
let s = "Hello there";
2
​
3
// Convert a string to a Vec<char>
4
let cvec: Vec<char> = s.chars().collect();
Copied!

How to convert vector of chars back to a String?

Carrying from the above example,
1
// Convert a string to a Vec<char>
2
let cvec: Vec<char> = s.chars().collect();
3
​
4
// Convert a Vec<char> into a String
5
let back: String = cvec.into_iter().collect();
Copied!
Last modified 1yr ago