Difference between revisions of "Textutils.urlEncode"
From ComputerCraft Wiki
m (Moved to CAT:APIFunctions) |
m (added outputs) |
||
| Line 13: | Line 13: | ||
sSafe = textutils.urlEncode(sUnsafe) | sSafe = textutils.urlEncode(sUnsafe) | ||
print(sSafe)</pre> | print(sSafe)</pre> | ||
| − | |output= | + | |output=http%3A%2F%2Fexample%2Ecom%2F%3Fview%3D?0%9AŒ87´A8+%40%21%21+3%2Dg%5Fdvv%5Bgf |
}} | }} | ||
{{Example | {{Example | ||
| Line 19: | Line 19: | ||
|code=<pre>sUnsafe = "€ @!! 3-g_dvv[gf" | |code=<pre>sUnsafe = "€ @!! 3-g_dvv[gf" | ||
sBaseURL = "http://example.com/?view=" | sBaseURL = "http://example.com/?view=" | ||
| − | sSafe = textutils. | + | sSafe = textutils.urlEncode(sUnsafe) |
sURL = sBaseURL .. sSafe | sURL = sBaseURL .. sSafe | ||
print(sURL)</pre> | print(sURL)</pre> | ||
| − | |output= | + | |output=http://example.com/?view=Œ84+%40%21%21+3%2Dg%5Fdvv%5Bgf |
}} | }} | ||
}} | }} | ||
[[Category:API_Functions]] | [[Category:API_Functions]] | ||
Revision as of 18:44, 18 January 2013
| 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
| 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 | http://example.com/?view=Œ84+%40%21%21+3%2Dg%5Fdvv%5Bgf |