Utf8.char: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Shared function}} Generates a string representing the character code points as arguments. ==Syntax== <syntaxhighlight lang="lua">string utf8.char ( [ int codepoints... ] )</syntaxhighlight> ===...")
 
No edit summary
Line 23: Line 23:


print( joined ) -- Hello World
print( joined ) -- Hello World
</syntaxhighlight>
</section>
<section name="Server" class="server" show="true">
This example takes 3 code points to generate the string "MTA".
<syntaxhighlight lang="lua">
local mta = utf8.char( 77, 84, 65 )
print(mta) -- MTA
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 00:54, 15 February 2016

Generates a string representing the character code points as arguments.

Syntax

string utf8.char ( [ int codepoints... ] )

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • codepoints: An argument sequence of code points representing the desired unicode characters.

Returns

Returns a string, which contains the representation of the code point arguments.

Example

Click to collapse [-]
Server

This example seperates an input string into single code points and then joins these back together, representing the original input string.

local input = "Hello World"
local codepoints = { utf8.byte( input, 1, utf8.len(input) ) }
local joined = utf8.char( unpack(codepoints) )

print( joined ) -- Hello World
Click to collapse [-]
Server

This example takes 3 code points to generate the string "MTA".

local mta = utf8.char( 77, 84, 65 )
print(mta) -- MTA
Click to collapse [-]
Client

This example takes the first 5 code points from the input string and then joins them back together.

local input = "Mutli Theft Auto"
local codepoints = {}

-- Extract first 5 characters (read: Mutli)
for index = 1, 5 do
    codepoints[index] = utf8.byte( input, index )
end

local output = ""

-- Join the first 5 characters together
for index = 1, #codepoints do
    output = output .. utf8.char( codepoints[index] )
end

outputConsole(output) -- Multi

See Also