Reputation: 9018
How do I replace the + with %2B:
Here is my code
x<-"asflj + ldjjsf ljsdlafj"
gsub("+","%2B", x)
my output is:
"%2Ba%2Bs%2Bf%2Bl%2Bj%2B %2B+%2B %2Bl%2Bd%2Bj%2Bj%2Bs%2Bf%2B %2Bl%2Bj%2Bs%2Bd%2Bl%2Ba%2Bf%2Bj%2B"
and I want it to be "asflj %20 ldjjsf ljsdlafj"
Upvotes: 1
Views: 157
Reputation: 61154
+
is a metacharacter then you can set fixed=TRUE
to skip it and get what you need.
> gsub("+","%2B", x, fixed=TRUE)
[1] "asflj %2B ldjjsf ljsdlafj"
Or skip it by using \\+
> gsub("\\+","%2B", x)
[1] "asflj %2B ldjjsf ljsdlafj"
Upvotes: 3