我有一个像这样的字符串:
x <- c("saw the revenant awesome experience must be seen on a big theatrical screen\ntherevenant","a lil sumn sumn i whipped up \U3e64653c\U3e30613c\U3e64623c\U3e64653c\U3e36623c\U3e61383ctherevenant")
如何使用 gsub() 删除 R 中以\n 或\U 开头的所有内容?
最佳答案
您可以使用 iconv
删除\U 字符,并使用 gsub
处理换行符。
x <- c("saw the revenant awesome experience must be seen on a big theatrical screen\ntherevenant","a lil sumn sumn i whipped up \U3e64653c\U3e30613c\U3e64623c\U3e64653c\U3e36623c\U3e61383ctherevenant")
> iconv(gsub("\\n", " ", x), to="ASCII", sub="")
[1] "saw the revenant awesome experience must be seen on a big theatrical screen therevenant"
[2] "a lil sumn sumn i whipped up therevenant"
关于删除 R 中以\n 或\U 开头的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35990875/