
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 Upper Function in Lua Programming
There are certain scenarios in our code that when we are working with the strings, we might want some string to be in uppercase, like consider a very basic and yet famous example of such scenario, the PAN number.
Imagine that you are making a web form in which there’s a field for the PAN number of the user, and since you know that PAN number can’t be in lowercases, we need to take the user input of that field and convert the string into its uppercase.
Converting a string to its uppercase in Lua is done by the string.upper() function.
Syntax
string.upper(s)
In the above syntax, the identifier s denotes the string which we are trying to convert into its uppercase.
Example
Let’s consider a very simple example of the same, where we will convert a string literal into its uppercase.
Consider the example shown below −
s = string.upper("abc") print(s)
Output
ABC
An important point to note about the string.upper() function is that it doesn’t modify the original string, it just does the modification to a copy of it and returns that copy. Let’s explore this particular case with the help of an example.
Example
Consider the example shown below −
s = "abc" s1 = string.upper("abc") print(s) print(s1)
Output
abc ABC
Also, if a string is already in its uppercase form then nothing will change.
Consider the example shown below −
Example
s = "A" string.upper("A") print(s)
Output
A