How to join a vector of strings (Vec<String>) into one string in Rust?
Hi! I recently started learning Rust and encountered a problem that seems trivial in other languages, but in Rust it's causing me difficulties.
I have a vector of strings: `Vec`. I want to join all the strings from this vector into one string, separating them with some delimiter, for example, a comma or a space.
In Python I would write `",".join(my_list)`. In JavaScript — `myArray.join(",")`. In Rust I tried to write something like `my_vec.join(",")`, but the compiler gives an error:
```rust
let words = vec!["hello".to_string(), "world".to_string(), "rust".to_string()];
let result = words.join(","); // error: no method named `join` found
```
I understand that Rust is strict about types, and `Vec` is not the same as a string slice. But how do I correctly join strings? Well
No answers yet.
Log in to leave an answer