string.byte

From ComputerCraft
Jump to: navigation, search

string.byte
Function
Syntax
string.byte()
Colon notation: str:byte()

Returns number
API string
Source Lua (source)

Return the byte of the first character in the given str. As string literals in Lua represent ASCII strings, this will most likely return ASCII codepoints. To convert a byte back into a string, use string.char.

ExampleExamplePrint the bytes of the user input
Read a character from the user, then print the byte of each letter, separated by spaces.
Code
for character in read():gmatch(".") do
  write(string.byte(character))
  write(" ")
end
Output Depends on what the user wrote. For instance, if they were to enter Hello World, the output would be 72 101 108 108 111 32 87 111 114 108 100.