# string.lower() function in Lua programming

LuaServer Side ProgrammingProgramming

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.

## Syntax

string.lower(s)

In the above syntax, the identifier s denotes the string which we are trying to convert into its lowercase.

## Example

Let’s consider a very simple example of the same, where we will convert a string literal into its lowercase.

Consider the example shown below −

Live Demo

s = string.lower("ABC")
print(s)

## Output

abc

An important point to note about the string.lower() 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 −

Live Demo

s = "ABC"
s1 = string.lower("ABC")
print(s)
print(s1)

## Output

ABC
abc

Also, if a string is already in its lowercase form then nothing will change.

## Example

Consider the example shown below −

Live Demo

s = "a"
string.lower("a")
print(s)

## Output

a
Updated on 19-Jul-2021 12:19:22