URL encoding: Difference between revisions

Added Crystal
No edit summary
(Added Crystal)
Line 484:
{{out}}
<pre>"http%3A%2F%2Ffoo%20bar%2F"</pre>
 
=={{header|Crystal}}==
The standard library <code>URI</code> class provides methods for both the RFC 3986 and HTML 5 standards. The RFC 3986 method defaults to replacing space characters with <code>%20</code> but will replace them with <code>+</code> instead if the optional parameter <code>space_to_plus</code> is true. The HTML 5 method has the opposite default behavior.
<lang crystal>require "uri"
 
puts URI.encode("http://foo bar/")
puts URI.encode("http://foo bar/", space_to_plus: true)
puts URI.encode_www_form("http://foo bar/")
puts URI.encode_www_form("http://foo bar/", space_to_plus: false)</lang>
{{out}}
<pre>http://foo%20bar/
http://foo+bar/
http%3A%2F%2Ffoo+bar%2F
http%3A%2F%2Ffoo%20bar%2F</pre>
 
=={{header|D}}==
Anonymous user