Difference between revisions of "Textutils.urlEncode"
From ComputerCraft Wiki
m (added outputs) |
(Removed a pointless, incorrect and confusing example.) |
||
(One intermediate revision by one other user not shown) | |||
Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=textutils.urlEncode | |name=textutils.urlEncode | ||
− | |args= | + | |args={{type|string}} text |
− | |returns= | + | |returns={{type|string}} safe for use on the internet |
|api=textutils | |api=textutils | ||
|addon=ComputerCraft | |addon=ComputerCraft | ||
|desc=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. | |desc=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. | ||
|examples= | |examples= | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{{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= | + | |code= local unsafeString = "€ @!! 3-g_dvv[gf" |
− | + | local baseUrl = "http<nowiki/>://example.com/?view=" | |
− | + | local safeString = '''textutils.urlEncode'''(unsafeString) | |
− | + | ||
− | print( | + | [[print]](baseUrl .. safeString) |
− | |output=http://example.com/?view=Œ84+%40%21%21+3%2Dg%5Fdvv%5Bgf | + | |output=http<nowiki/>://example.com/?view=Œ84+%40%21%21+3%2Dg%5Fdvv%5Bgf |
}} | }} | ||
}} | }} | ||
[[Category:API_Functions]] | [[Category:API_Functions]] |
Latest revision as of 06:41, 14 October 2014
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 text) |
Returns | string safe for use on the internet |
Part of | ComputerCraft |
API | textutils |
Examples
Example | |
Create a safe URL from a base URL and a string to be inserted. | |
Code |
local unsafeString = "€ @!! 3-g_dvv[gf" local baseUrl = "http://example.com/?view=" local safeString = textutils.urlEncode(unsafeString) print(baseUrl .. safeString) |
Output | http://example.com/?view=Œ84+%40%21%21+3%2Dg%5Fdvv%5Bgf |