0

I need to split a string where there is more than one space into list elements. Let's say I have the following string:

"My name     is Bob and   I like programming."

I tried the following code:

library(stringr)
string <- "My name     is Bob and   I like programming."
strsplit(string,"\\s+")

Which gives the result:

[[1]]
[1] "My"           "name"         "is"          
[4] "Bob"          "and"          "I"           
[7] "like"         "programming."

However, I would like this result instead:

[[1]]
[1] My name

[[2]]
[1] is Bob and 

[[3]]
[1] I like programming.

Any help is appreciated!

AyeTown
  • 831
  • 1
  • 5
  • 20

0 Answers0