encoding - How to convert \\u0026 to & with ruby -


i having pretty basic problem have following string:

url="http://www.autokaupat.net/jyv%e4skyl%e4/\\u0026view=2254630" 

the html encoding not problem, \\u0026 has converted & in order work want to. following approach doesn't work me, although seems working many others:

url.force_encoding('utf-8') 

this works if remove 1 of leading backslashes.

any thoughts on how fixed?

the character & represent plain string \u0026 in url. 6 characters rather single character represented unicode escape. force_encoding won't job in case.

try following, extract unicode liked sequence in string , replace them actual character @ code point.

url="http://www.autokaupat.net/jyv%e4skyl%e4/\\u0026view=2254630" url.gsub!(/\\u([a-f0-9]{4,5})/i){ [$1.hex].pack('u') } puts url #=> http://www.autokaupat.net/jyv%e4skyl%e4/&view=2254630 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -