-1

I would like to receive a:

"Hello, I would like to meet you"

and convert to:

["Hello,", "I", "would", "like", "to", "meet", "you"]

how could I make that?

NrBanMex
  • 305
  • 2
  • 8

1 Answers1

2

There is a dedicated method for str to do this called split(). You can then use collect() to put the result in a Vec.

In your case:

fn main() {
    let original = "Hello, I would like to meet you";
    let split = original.split(' ');
    
    let vec: Vec<_> = split.collect();
    
    println!("{:?}", vec);
}
Emoun
  • 2,297
  • 1
  • 13
  • 20