Utf8.char: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (small tweaks) |
||
(One intermediate revision by one other user not shown) | |||
Line 2: | Line 2: | ||
{{Shared function}} | {{Shared function}} | ||
Generates a string representing the character | Generates a string representing the character codepoints as arguments. | ||
==Syntax== | ==Syntax== | ||
Line 9: | Line 9: | ||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{OptionalArg}} | {{OptionalArg}} | ||
*'''codepoints:''' An argument sequence of code points representing the desired unicode characters. | *'''codepoints:''' An variable argument sequence of code points representing the desired unicode characters. | ||
===Returns=== | ===Returns=== | ||
Returns a ''string'' | Returns a ''string'' representation of the codepoints passed. | ||
==Example== | ==Example== | ||
<section name="Server" class="server" show="true"> | <section name="Server" class="server" show="true"> | ||
This example | This example separates an input string into single codepoints and then joins these back together, representing the original input string. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local input = "Hello World" | local input = "Hello World" | ||
Line 26: | Line 26: | ||
</section> | </section> | ||
<section name="Server" class="server" show="true"> | <section name="Server" class="server" show="true"> | ||
This example takes | This example takes three code points to generate the string "MTA". | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local mta = utf8.char( 77, 84, 65 ) | local mta = utf8.char( 77, 84, 65 ) | ||
print(mta) -- MTA | print( mta ) -- MTA | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
<section name="Client" class="client" show="true"> | <section name="Client" class="client" show="true"> | ||
This example takes the first | This example takes the first five code points from the input string and then joins them back together. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local input = "Mutli Theft Auto" | local input = "Mutli Theft Auto" | ||
Line 50: | Line 50: | ||
end | end | ||
outputConsole(output) -- Multi | outputConsole( output ) -- Multi | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> |
Latest revision as of 18:21, 15 February 2016
Generates a string representing the character codepoints 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 variable argument sequence of code points representing the desired unicode characters.
Returns
Returns a string representation of the codepoints passed.
Example
Click to collapse [-]
ServerThis example separates an input string into single codepoints 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 [-]
ServerThis example takes three code points to generate the string "MTA".
local mta = utf8.char( 77, 84, 65 ) print( mta ) -- MTA
Click to collapse [-]
ClientThis example takes the first five 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
Shared
- utf8.byte
- utf8.char
- utf8.charpos
- utf8.escape
- utf8.find
- utf8.fold
- utf8.gmatch
- utf8.gsub
- utf8.insert
- utf8.len
- utf8.lower
- utf8.match
- utf8.ncasecmp
- utf8.next
- utf8.remove
- utf8.reverse
- utf8.sub
- utf8.title
- utf8.upper
- utf8.width
- utf8.widthindex