简体   繁体   中英

Removing certain characters from a string in 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

....

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.

This should work

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

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"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM