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@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.
______________________________________________
R-help@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.