🦀
Rust Cookbook
  • Introduction
  • Rust Introduction
  • Collections
    • Hashing
  • Text Processing
    • Splitting a string
    • Converting a string to vectors and back
    • Twoway
  • Benchmarking
    • criterion
  • Testing
  • Package Management
    • Cargo workspaces
  • Concurrent Programming
    • Actor model
      • Actix actors
      • Bastion
  • Parallel Programming
    • Ryaon
  • Optimisations
    • Cache alignment
  • TODO
Powered by GitBook
On this page
  • How to convert a String to a vector of chars?
  • How to convert vector of chars back to a String?
  1. Text Processing

Converting a string to vectors and back

How to convert a String to a vector of chars?

let s = "Hello there";

// Convert a string to a Vec<char>
let cvec: Vec<char> = s.chars().collect();

How to convert vector of chars back to a String?

Carrying from the above example,

// Convert a string to a Vec<char>
let cvec: Vec<char> = s.chars().collect();

// Convert a Vec<char> into a String
let back: String = cvec.into_iter().collect();
PreviousSplitting a stringNextTwoway

Last updated 5 years ago