Utf8.byte: Difference between revisions
Jump to navigation
Jump to search
m (fix optional args) |
No edit summary |
||
Line 28: | Line 28: | ||
print( "Codepoint @ ".. index .." = ".. codepoint ) | print( "Codepoint @ ".. index .." = ".. codepoint ) | ||
end | end | ||
</syntaxhighlight> | |||
Output: | |||
<syntaxhighlight lang="lua"> | |||
Codepoint @ 1 = 72 | |||
Codepoint @ 2 = 101 | |||
Codepoint @ 3 = 108 | |||
Codepoint @ 4 = 108 | |||
Codepoint @ 5 = 111 | |||
Codepoint @ 6 = 32 | |||
Codepoint @ 7 = 87 | |||
Codepoint @ 8 = 111 | |||
Codepoint @ 9 = 114 | |||
Codepoint @ 10 = 108 | |||
Codepoint @ 11 = 100 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> |
Revision as of 02:45, 15 February 2016
Returns the code points for the i-th through j-th character of the string passed.
Syntax
int,... utf8.byte ( string input [, int i = 1, int j = 1 ] )
Required Arguments
- input: A string character sequence
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.
- i: A number representing the beginning position.
- j: A number representing the ending position.
Returns
Returns a sequence of number values from the original string if successful, nil otherwise.
Example
Click to collapse [-]
ServerThis example will print every code point in the input string to the server console.
local input = "Hello World" local codepoints = { utf8.byte( input, 1, utf8.len(input) ) } for index, codepoint in ipairs( codepoints ) do print( "Codepoint @ ".. index .." = ".. codepoint ) end
Output:
Codepoint @ 1 = 72 Codepoint @ 2 = 101 Codepoint @ 3 = 108 Codepoint @ 4 = 108 Codepoint @ 5 = 111 Codepoint @ 6 = 32 Codepoint @ 7 = 87 Codepoint @ 8 = 111 Codepoint @ 9 = 114 Codepoint @ 10 = 108 Codepoint @ 11 = 100
Click to collapse [-]
ClientThis example will print the code point of the first character (read: 'M') in the string literal.
local first = utf8.byte( "Multi Theft Auto", 1, 1 ) outputConsole( first ) -- 77
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