【发布时间】:2021-03-10 00:27:59
【问题描述】:
我有如下文字。
"The comm unity is here to help you wi th specific co ding"
我想删除句子中的三个空格,同时留下一个空格。
我试过了
gsub(text, " ", "")
但它不起作用。
【问题讨论】:
我有如下文字。
"The comm unity is here to help you wi th specific co ding"
我想删除句子中的三个空格,同时留下一个空格。
我试过了
gsub(text, " ", "")
但它不起作用。
【问题讨论】:
要删除一个单词内的三个空格,请使用:
x <- "The comm unity is here to help you wi th specific co ding"
output <- gsub("\\b[ ]{3}\\b", "", x)
output
[1] "The community is here to help you with specific coding"
【讨论】:
这是否有效,删除多个空格:
st <- "The comm unity is here to help you wi th specific co ding"
st
[1] "The comm unity is here to help you wi th specific co ding"
gsub('\\s{2,}','',st)
[1] "The community is here to help you with specific coding"
【讨论】: