
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
String Byte Function in Lua Programming
The string.byte() function is one of the most widely used Lua string library functions that takes a character or a string as an argument and then converts that character into its internal numeric representations.
The character to internal numeric representations can be easily interpreted from the ASCII table.
Syntax
string.byte(ch) or string.byte(ch,idx)
In the above representation of the string.byte() function, the ch identifier represents the character that we want to convert into a decimal value. Also, the idx identifier represents a character at that index of the string passed as an argument.
Let’s consider a few examples where we will make use of the string.byte() function.
Example
Consider an example shown below −
s = string.byte("a") print(s)
Output
97
We can also pass a string in the argument to the string.byte() function, and if we don’t specify any index then that string will only print the first character’s internal integer representation.
Example
Consider the example shown below −
s = string.byte("abc") print(s)
Output
97
Example
Let’s consider an example where we will pass an index as the second argument to the string.byte() function. Consider the example shown below −
s = string.byte("abc",2) print(s)
Output
98
Note − The indexing of the string starts at 1.