2016-10-28 58 views
-1

我有以下字符串:替換爲%20空間

url <- https://www.google.mu/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=green carot 

我想更換綠色之間的空間和%carot 20

>url 
https://www.google.mu/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=green%20carot 

回答

1

如果這一(爲一個直SRING替換)是

> gsub(" ","%20"),url 

雖然,一個URL編碼功能會更好

6

有一些功能與URL工作。 在基礎R使用URLencode

url <- "https://www.google.mu/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=green carot" 

URLencode(url) 
#> [1] "https://www.google.mu/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=green%20carot"