gpt4 book ai didi

ruby-on-rails - 解析字符串以添加到 URL 编码的 URL

转载 作者:数据小太阳 更新时间:2023-10-29 06:19:56 25 4
gpt4 key购买 nike

给定字符串:

"Hello there world"

如何创建这样的 URL 编码字符串:

"Hello%20there%20world"

我还想知道如果字符串也有其他符号该怎么办,比如:

"hello there: world, how are you"

最简单的方法是什么?我打算解析然后为此构建一些代码。

最佳答案

在 2019 年,URI.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"

关于ruby-on-rails - 解析字符串以添加到 URL 编码的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17375947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com