string.byte
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.
|
|||
| Read a character from the user, then print the byte of each letter, separated by spaces. | |||
| Code | <nowiki>
for character in read():gmatch(".") do
write(string.byte(character))
write(" ")
end
</nowiki>
|
||
| 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. |
||
Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Lua |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CC:Tweaked |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string.byte Function | |
|---|---|
|
Syntax string.byte(
Colon notation: str:byte() | |
| Returns | number |
| API | string |
| Source | Lua (source) |
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.