我有一个像
这样的字符串a <- "Hi. I m cool, but I need help!"
作为我想要的输出
"hi" "." "I" "m" "cool" "," "but" "I" "need" "help" "!"
此外,我不想使用额外的包。
答案 0 :(得分:1)
我们可以使用strsplit
a1 <- strsplit(a, '\\s|(?=[!,.])\\s*', perl = TRUE)[[1]]
a1[nzchar(a1)]
#[1] "Hi" "." "I" "m" "cool" "," "but" "I" "need" "help" "!"