考虑到字符串:
"Hello there world"
如何创建URL编码的字符串,如下所示:
"Hello%20there%20world"
我也想知道如果字符串也有其他符号,比如:
"hello there: world, how are you"
最简单的方法是什么?我要分析并构建一些代码.
考虑到字符串:
"Hello there world"
如何创建URL编码的字符串,如下所示:
"Hello%20there%20world"
我也想知道如果字符串也有其他符号,比如:
"hello there: world, how are you"
最简单的方法是什么?我要分析并构建一些代码.
2019年,乌里.encode已过时,不应使用.
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"