
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
Found 33676 Articles for Programming

77K+ Views
Another important function of the Lua’s string library is the string.sub() function. The string.sub() function is used to extract a piece of the string.The string.sub() function takes three arguments in general, the first argument being the name of the string from which we want to extract a piece, the second argument is the i-th index or say, the starting index of the string piece that we want, and the third and the last argument is the j-th index of the last index of the string piece we want.It should be noted that both the starting index and the ending index, ... Read More

7K+ Views
There are certain scenarios in our code that when we are working with the strings, we might want some string to be in lowercase, like consider a very basic case of an API which is using an authentication service, and the password for that authentication service should in lowercase, and in that case, we need to convert whatever the password the user enters into lowercase.Converting a string to its lowercase in Lua is done by the string.lower() function.Syntaxstring.lower(s)In the above syntax, the identifier s denotes the string which we are trying to convert into its lowercase.ExampleLet’s consider a very simple ... Read More

27K+ Views
There are scenarios when we want to change a pattern that we found in a string with our pattern, and in Lua for that we have a famous library function, named the string.gsub() function.The string.gsub() function has three arguments, the first is the subject string, in which we are trying to replace a substring to another substring, the second argument is the pattern that we want to replace in the given string, and the third argument is the string from which we want to replace the pattern.Syntaxstring.gsub(x, a, b)In the above syntax, the x identifier is used to denote the ... Read More

16K+ Views
There are cases when we want to format strings which will help us to print the output in a particular format.When we use the string.format() function it returns a formatted version of its variable number of arguments following the description given by its first argument, the so-called format string.The format string that we get the output, is similar to those of the printf function of standard C: It is composed of regular text and directives, which control where and how each argument must be placed in the formatted string.Syntaxstring.format(“s = %a”)The string.format() syntax above contains an identifier s which is ... Read More

22K+ Views
string.find() is one of the most powerful library functions that is present inside the string library.Lua doesn’t use the POSIX regular expression for pattern matching, as the implementation of the same takes 4, 000 lines of code, which is actually bigger than all the Lua standard libraries together. In place of the POSIX pattern matching, the Lua’s implementation of pattern matching takes less than 500 lines.The string.find() function is used to find a specific pattern in a given string, it normally takes two arguments, the first argument being the string in which the pattern we are trying to search, and ... Read More

7K+ Views
There are so many scenarios where you might want to convert a decimal value into a character representation. The character representation of a decimal or integer value is nothing but the character value, which one can interpret using the ASCII table.In Lua, to convert a decimal value to its internal character value we make use of the string.char() function.Syntaxstring.char(I)In the above syntax, the identifier I represents the decimal value which we want to convert into a character.ExampleLet’s consider a very simple example, where you are given different decimal values, and you want to convert them to a character value.Consider the ... Read More

12K+ Views
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.Syntaxstring.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 ... Read More

11K+ Views
One of the most used functions in Lua is the sort function which is provided by the Lua library which tables a table as an argument and sorts the values that are present inside the table.The sort function also takes one more argument with the table and that argument is a function which is known as the order function. This order function is used to provide the logic if we want to sort the elements of the table in a certain order.The order function takes two arguments, and these two arguments must return true if the first argument should come ... Read More

713 Views
There are very few sections we will explore the possibility of making use of a semicolon in Lua. Majority of the code doesn’t require it, while there are some cases where we might need them.ExampleLet’s consider a case where the use of semicolon seems necessary. Consider the example shown below − Live Demolocal a, b=10, 20 print(a+b)The above statement in Lua is perfectly valid and it works like a charm.Output30ExampleWhat if we change the code above and put it in the same line? Would it still be a valid Lua code? Let’s try it out. Consider the code shown below −local ... Read More

12K+ Views
The select function in Lua is used to return the number of arguments that are passed into it as an argument. It can be used in two forms, the first one includes passing an index and then it will return the numbers that are passed after that number into the function as an argument in a list format, the other pattern is if we pass the length operator as a first argument, in that case it simply returns a count of the multiple arguments that are provided.ExampleLet’s explore both the cases in the examples shown below.Case 1 Live Demoprint(select(1, "a", "b", ... Read More