我有網址http://localhost:3000/en/invest_offers?utf8=blahblahblah
。我如何獲得?utf8=blahblahblah
網址的一部分?謝謝!Ruby:從字符串中刪除
0
A
回答
3
使用URI::parse
,URI::Generic#query
:
require 'uri'
url = 'http://localhost:3000/en/invest_offers?utf8=blahblahblah'
URI.parse(url)
# => #<URI::HTTP:0x0000000213aae0 URL:http://localhost:3000/en/invest_offers?utf8=blahblahblah>
URI.parse(url).query
# => "utf8=blahblahblah"
6
待辦事項如下使用URI::Generic.query
:
require 'uri'
URI("http://localhost:3000/en/invest_offers?utf8=blahblahblah").query
# => "utf8=blahblahblah"
1
執行以下操作: -
require 'uri'
url = 'http://localhost:3000/en/invest_offers?utf8=blahblahblah'
parsed_url = URI.parse(url)
,如果你只是想查詢字符串部分像"utf8=blahblahblah"
你應該做
parsed_url.query
,如果你想獲得"blahblahblah"
, 你應該做的
params["utf8"]
否則
p = CGI.parse(parsed_url.query)
# p is now {"utf8"=>["blahblahblah"]}
p["utf8"].first
#=> "blahblahblah"
相關問題
- 1. Ruby從字符串中刪除空行
- 2. 如何從Ruby字符串中刪除字符串「\ n」?
- 3. Ruby - 刪除字符串?
- 4. Ruby - 刪除字符串中的短字
- 5. 從Ruby中的字符串中刪除非UTF字符?
- 6. 從字符串中刪除字符串
- 7. 從字符串中刪除字符串
- 8. Ruby,從字符串中刪除最後N個字符?
- 9. 從字符串中刪除
- 10. 從字符串中刪除()
- 11. 從字符串中刪除「
- 12. 從字符串中刪除「@」
- 13. VB.NET - 從字符串中刪除字符
- 14. 從c字符串中刪除字符
- 15. 從字符串中刪除Unicode字符
- 16. 從字符串中刪除字符
- 17. 從Java字符串中刪除字符
- 18. 從字符串中刪除字符C
- 19. datagridview從字符串中刪除'&'字符
- 20. C從字符串中刪除字符
- 21. 從字符串中刪除字符
- 22. Fortran:從字符串中刪除字符
- 23. jQuery從字符串中刪除' - '字符
- 24. 從字符串中刪除字符?
- 25. 從字符串中刪除字符
- 26. Python:從字符串中刪除字符
- 27. 從字符串中刪除字符[i]
- 28. C++從字符串中刪除字符
- 29. 從C字符串中刪除字符
- 30. 使用擦除和刪除從字符串中刪除字符
您可以找到查詢屬性[這裏](HTTP:/ /ruby-doc.org/stdlib-2.1.0/libdoc/uri/rdoc/URI/Generic.html#query)。 – falsetru
@falsetru謝謝,我能夠看到,但沒有從文檔中獲得鏈接,您是如何得到它的?我仍在搜索:) –
我檢查了元素的'name'屬性。 – falsetru