[R] How to remove backslash
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Fri Sep 21 12:48:55 CEST 2018
Hello,
The backslash is not a character of the string str. test it with nchar:
str = '<span id=\"ctl00'
nchar(str)
#[1] 15
It is there just to escape the double quotes.
if you want a backslash you would need to escape it, like in str1.
str1 = '<span id=\\"ctl00'
nchar(str1)
#[1] 16
Now yes, you can remove it.
str2 <- gsub("\\", "", str1, fixed = TRUE)
identical(str, str2)
#[1] TRUE
Hope this helps,
Rui Barradas
Às 11:34 de 21/09/2018, Christofer Bogaso escreveu:
> Hi,
>
> I have below string where I am trying to remove Backslash from. I tried
> with gsub() function, however failed to remove that:
>
>> str = '<span id=\"ctl00'
>> gsub("\\", "", str)
> Error in gsub("\\", "", str) :
> invalid regular expression '\', reason 'Trailing backslash'
>
>
> Any pointer to the right approach?
>
> Thanks for your time
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list