字符串是"\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\tLocation\r\n\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\tSan Francisco, CA;Oakland, CA",我希望它显示为"Location","San Francisco, CA;Oakland, CA".
这有功能吗?谢谢!
您可以使用正则表达式删除特殊字符:
x <-"\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\tLocation\r\n\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\tSan Francisco, CA;Oakland, CA"
gsub('[\r\n\t]', '', x)
Run Code Online (Sandbox Code Playgroud)
但是,如果你真的有一个字符串与所有这些\答案变得更像是:
gsub('\\\\[a-z]', '', x)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6246 次 |
| 最近记录: |