.byte()
Anonymous contributor
Published Sep 10, 2023
Contribute to Docs
The string.byte()
function takes a character or a string as an argument and returns an ASCII (decimal) equivalent internal numeric representation.
Syntax
string.byte(s, n)
The function can take two arguments, where the s
parameter is a character or string and n
is the index of the string passed as an argument. Passing only one argument will set n
to 1
.
Example 1
The example below demonstrates the use of the .byte()
method.
print(string.byte('a'))print(string.byte('9'))print(string.byte(9))print(string.byte(' '))print(string.byte(';'))
This will return the following output:
9757573259
Example 2
This example demonstrates the use of .byte
with a second argument:
print(string.byte('abca', 4))print(string.byte(998877, 1))print(string.byte(998877, 3))print(string.byte(998877, 5))
This will return the following results.
97575655
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Lua on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Lua
Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.Beginner Friendly4 hours