Prev / Next

2003-07-20 / URI decode

Ruby について Part 4
http://pc2.2ch.net/test/read.cgi/tech/1056944114/191-202 より

URI.decode を使う

require 'uri'
$KCODE = 's'
str = '\x95\x5c\x94\x5c'

p URI.decode(str.gsub(/\\x/, '%'))

pack を使う

str = '\x95\x5c\x94\5c'
puts str.scan(/[0-9A-Fa-f]+/).collect{|x| x.hex}.pack('C*')

eval を使う

src = "\\x95\\x5c\\x94\\x5c" ; dst = eval("%(#{str})")

comments powered by Disqus