解析字符串以添加到 URL 编码的 URL [英] Parsing string to add to URL-encoded URL
本文介绍了解析字符串以添加到 URL 编码的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定字符串:
"Hello there world"
如何创建这样的 URL 编码字符串:
how can I create a URL-encoded string like this:
"Hello%20there%20world"
我也想知道如果字符串也有其他符号该怎么办,例如:
I would also like to know what to do if the string has other symbols too, like:
"hello there: world, how are you"
最简单的方法是什么?我打算解析然后为此构建一些代码.
What would is the easiest way to do so? I was going to parse and then build some code for that.
推荐答案
2019 年,URI.encode 已过时,不应使用.
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"
这篇关于解析字符串以添加到 URL 编码的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文