π¦
π¦
π¦
π¦
Rust Cookbook
π‘
π
π¦
Searchβ¦
Introduction
Rust Introduction
Collections
Text Processing
Splitting a string
Converting a string to vectors and back
Twoway
Benchmarking
Testing
Package Management
Concurrent Programming
Parallel Programming
Optimisations
TODO
Powered By
GitBook
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!
Previous
Splitting a string
Next
Twoway
Last modified
2yr ago
Copy link
Contents
How to convert a String to a vector of chars?
How to convert vector of chars back to a String?