Parsing string to add to URL-encoded URL

后端 未结 4 1768
误落风尘
误落风尘 2020-12-08 01:25

Given the string:

\"Hello there world\"

how can I create a URL-encoded string like this:

\"Hello%20there%20world\"
<         


        
4条回答
  •  无人及你
    2020-12-08 02:19

    In 2019, URI.encode is obsolete and should not be used.


    require 'uri'
    
    URI.encode("Hello there world")
    #=> "Hello%20there%20world"
    URI.encode("hello there: world, how are you")
    #=> "hello%20there:%20world,%20how%20are%20you"
    
    URI.decode("Hello%20there%20world")
    #=> "Hello there world"
    

提交回复
热议问题