Type Function Library string.* Return value Number Revision Release 2022.3683 Keywords string, byte, numerical codes, characters See also string.char()
Returns the internal numerical codes of the characters in a string.
string.byte( s [, i [, j]] ) s:byte( [, i [, j]] )
String. The string.
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
.
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