How to Convert “space” into “%20” with R

守給你的承諾、 提交于 2019-12-04 04:01:05

问题


Referring the title, I'm figuring how to convert space between words to be %20 .

For example,

> y <- "I Love You"

How to make y = I%20Love%20You

> y
[1] "I%20Love%20You"

Thanks a lot.


回答1:


gsub() is one option:

R> gsub(pattern = " ", replacement = "%20", x = y)
[1] "I%20Love%20You"



回答2:


Another option would be URLencode():

y <- "I love you"
URLencode(y)
[1] "I%20love%20you"



回答3:


The function curlEscape() from the package RCurl gets the job done.

library('RCurl')
y <- "I love you"
curlEscape(urls=y)
[1] "I%20love%20you"


来源:https://stackoverflow.com/questions/11116446/how-to-convert-space-into-20-with-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!