Difference between revisions of "Textutils.urlEncode"

From ComputerCraft Wiki
Jump to: navigation, search
(Created page, but not the outputs of the functions, as I can't run Minecraft on this computer)
 
Line 10: Line 10:
 
{{Example
 
{{Example
 
|desc=Create a safe string from another string full of invalid characters. '''This is incorrect usage!'''
 
|desc=Create a safe string from another string full of invalid characters. '''This is incorrect usage!'''
|code=sUnsafe = "http://example.com/?view=€ @!! 3-g_dvv[gf"<br />sSafe = textutils.urlEncode(sUnsafe)<br />print(sSafe)
+
|code=<pre>sUnsafe = "http://example.com/?view=€ @!! 3-g_dvv[gf"
 +
sSafe = textutils.urlEncode(sUnsafe)
 +
print(sSafe)</pre>
 
|output=(to be specified - I don't have CC on this computer)
 
|output=(to be specified - I don't have CC on this computer)
 
}}
 
}}
 
{{Example
 
{{Example
 
|desc=Create a safe URL from a base URL and a string to be inserted.
 
|desc=Create a safe URL from a base URL and a string to be inserted.
|code=sUnsafe = "€ @!! 3-g_dvv[gf"<br />sBaseURL = "http://example.com/?view="<br />sSafe = textutils.urlencode(sUnsafe)<br />sURL = sBaseURL .. sSafe<br />print(sURL)
+
|code=<pre>sUnsafe = "€ @!! 3-g_dvv[gf"
 +
sBaseURL = "http://example.com/?view="
 +
sSafe = textutils.urlencode(sUnsafe)
 +
sURL = sBaseURL .. sSafe
 +
print(sURL)</pre>
 
|output=(same here)
 
|output=(same here)
 
}}
 
}}
 
}}
 
}}

Revision as of 01:44, 5 November 2012


Grid Redstone.png  Function textutils.urlEncode
Replaces certain characters in a string to make it safe for use on the internet. Note that it is a string function and will even replace characters that are allowed in URLs. Use this only for text to be inserted in an URL, not the URL itself.
Syntax textutils.urlEncode(string)
Returns A string safe for use on the internet
Part of ComputerCraft
API textutils

Examples

Grid paper.png  Example
Create a safe string from another string full of invalid characters. This is incorrect usage!
Code
sUnsafe = "http://example.com/?view=€ @!! 3-g_dvv[gf"
sSafe = textutils.urlEncode(sUnsafe)
print(sSafe)
Output (to be specified - I don't have CC on this computer)



Grid paper.png  Example
Create a safe URL from a base URL and a string to be inserted.
Code
sUnsafe = "€ @!! 3-g_dvv[gf"
sBaseURL = "http://example.com/?view="
sSafe = textutils.urlencode(sUnsafe)
sURL = sBaseURL .. sSafe
print(sURL)
Output (same here)