How to URL encode a string in Ruby

后端 未结 8 836
醉梦人生
醉梦人生 2020-12-02 05:34

How do I URI::encode a string like:

\\x12\\x34\\x56\\x78\\x9a\\xbc\\xde\\xf1\\x23\\x45\\x67\\x89\\xab\\xcd\\xef\\x12\\x34\\x56\\x78\\x9a
         


        
8条回答
  •  伪装坚强ぢ
    2020-12-02 06:25

    str = "\x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a"
    require 'cgi'
    CGI.escape(str)
    # => "%124Vx%9A%BC%DE%F1%23Eg%89%AB%CD%EF%124Vx%9A"
    

    Taken from @J-Rou's comment

提交回复
热议问题