Utf8.escape: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Shared function}} Escapes a string to a UTF-8 format string. It supports several escape formats: *'''%ddd:''' where ddd is a decimal number with variable length *...")
 
No edit summary
Line 24: Line 24:


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local output = utf8.escape("%123 %u123 %{123} %u{123} %xABC %x{ABC}")
local output = utf8.escape( "%123 %u123 %{123} %u{123} %xABC %x{ABC}" )
print( output ) -- { { { { ઼ ઼
print( output ) -- { { { { ઼ ઼
local output = utf8.escape( "%%123 %? %d %%u" )
print( output ) -- %123 ? d %u
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 01:51, 15 February 2016

Escapes a string to a UTF-8 format string. It supports several escape formats:

  • %ddd: where ddd is a decimal number with variable length
  • %{ddd}: same as above, but enclosed in brackets
  • %uddd: same as %ddd, 'u' stands for unicode
  • %u{ddd}: same as above, but enclosed in brackets
  • %xhhh: hexadigit version of %ddd
  • %x{hhh}: same as above, but enclosed in brackets
  • %?: where '?' stands for any other character to be escaped

Syntax

string utf8.escape ( string input )

Required Arguments

  • input: A string character sequence

Returns

Returns a string containing the UTF-8 characters from the original string.

Example

Click to collapse [-]
Server
local output = utf8.escape( "%123 %u123 %{123} %u{123} %xABC %x{ABC}" )
print( output ) -- { { { { ઼ ઼

local output = utf8.escape( "%%123 %? %d %%u" )
print( output ) -- %123 ? d %u

See Also