Replace a character in a text

后端 未结 1 1070
渐次进展
渐次进展 2021-01-25 06:57

How do I replace the + with %2B:

Here is my code

x<-\"asflj + ldjjsf ljsdlafj\"
gsub(\"+\",\"%2B\",  x)

my output is:



        
相关标签:
1条回答
  • 2021-01-25 07:36

    + 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"
    
    0 讨论(0)
提交回复
热议问题