string.byte()

Type Function
Library string.*
Return value Number
Revision 2017.3179
Keywords string, byte, numerical codes, characters
See also string.char()

Overview

Returns the internal numerical codes of the characters in a string.

Syntax

string.byte( s [, i [, j]] )

s:byte( [, i [, j]] )
s (required)

String. The string.

i [, j] (optional)

Number. Specify the characters of the string s[i], s[i+1], ..., s[j] for which to get the codes. The default value for i is 1; the default value for j is i.

Example

print( string.byte( "ABCDE" ) )        ---> 65
print( string.byte( "ABCDE", 1 ) )     ---> 65
print( string.byte( "ABCDE", 3, 5 ) )  ---> 67   68   69
print( string.byte( "ABCDE", 0 ) )     ---> nil
print( string.byte( "ABCDE", -1 ) )    ---> 69
 
local s = "ABCDE"
print( s:byte( 3, 4 ) )                ---> 67   68