42

我在 R 中有一个包含大量单词的字符串。查看字符串时,我得到大量文本,其中包括类似于以下内容的文本:

>docs

....

\u009cYes yes for ever for ever the boys cried in their ringing voices with softened faces

....

所以我想知道如何从字符串中删除这些 \u009 字符(所有这些字符,其中一些数字略有不同)。我尝试过使用gsub(),但这对于从字符串中删除内容无效。

4

2 回答 2

58

这应该工作

gsub('\u009c','','\u009cYes yes for ever for ever the boys ')
"Yes yes for ever for ever the boys "

这里 009c 是 unicode 的十六进制数。您必须始终指定 4 个十六进制数字。如果你有很多,一种解决方案是用管道将它们分开:

gsub('\u009c|\u00F0','','\u009cYes yes \u00F0for ever for ever the boys and the girls')

"Yes yes for ever for ever the boys and the girls"
于 2013-03-02T04:06:12.660 回答
12

尝试: gsub('\\$', '', '$5.00$')

于 2016-04-19T10:53:29.060 回答