从 R 中的字符串中删除某些字符 [英] Removing certain characters from a string in R

查看:46
本文介绍了从 R 中的字符串中删除某些字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a string in R which contains a large amount of words. When viewing the string I get a large amount of text which includes text similar to the following:

>docs

....

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

....

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

So I'm wondering how to remove these \u009 characters (all of them, some of which have slightly different numbers) from the string. I've tried using gsub(), but that wasn't effective in removing the content from the strings.

推荐答案

这应该可行

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

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

Here 009c is the hexadecimal number of unicode. You must always specify 4 hexadecimal digits. If you have many , one solution is to separate them by a pipe:

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"

这篇关于从 R 中的字符串中删除某些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆