[R] how to replace a single forward slash with a double backward slash in a string?

David Winsemius dwinsemius at comcast.net
Sun Dec 13 19:08:50 CET 2009


On Dec 13, 2009, at 1:00 PM, Sean Zhang wrote:

> Dear R-helpers.
>
> Can someone kindly tell me how to replace a single forward slash  
> with double
> backward slash in a string?
>
> i.e.,  from  "a/b" to "a\\b"

 > sub("/", "\\\\","a/b")
  #the backslashes need to be doubled because they are the escape  
character.
[1] "a\\b"

>
> Many thanks in advance.
>
> -Sean
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list