Jump to content

URL decoding: Difference between revisions

Added Wren
(Added Wren)
Line 1,615:
<pre>Encoded URL: http%3A%2F%2Ffoo%20bar%C3%A8%2F
Decoded URL: http://foo barè/</pre>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<lang ecmascript>import "/fmt" for Conv
 
var urlDecode = Fn.new { |enc|
var res = ""
var i = 0
while (i < enc.count) {
var c = enc[i]
if (c == "\%") {
var b = Conv.atoi(enc[i+1..i+2], 16)
res = res + String.fromByte(b)
i = i + 3
} else {
res = res + c
i = i + 1
}
}
return res
}
 
// We need to escape % characters in Wren as % is otherwise used for string interpolation.
var encs = [
"http\%3A\%2F\%2Ffoo\%20bar\%2F",
"google.com/search?q=\%60Abdu\%27l-Bah\%C3\%A1"
]
for (enc in encs)System.print(urlDecode.call(enc))</lang>
 
{{out}}
<pre>
http://foo bar/
google.com/search?q=`Abdu'l-Bahá
</pre>
 
=={{header|XPL0}}==
9,492

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.