Skip to content

find and replace characters in a string

4 messages · Shane Carey, arun, Rui Barradas +1 more

#
txt<-? "LOI ."
gsub("[.]","%",txt)
#[1] "LOI %"
A.K.
#
Hello,

The period is a metacharacter so you have to escape it.
The period is escaped with a '\'. In it's turn, '\' is a metacharacter 
so it needs to be escaped. Hence the double'\\'.

x <- "LOI ."
gsub("\\.", "(%)", x)


Hope this helps,

Rui Barradas

Em 27-03-2013 16:09, Shane Carey escreveu:
#
Although I am not an expert, this is simple.

txt<-  "LOI ."
gsub(".","%",txt, fixed=TRUE)

Regards
Petr