Vital.sandbox
String

string.lower

Shared

Converts all uppercase letters to lowercase


Syntax

local result = string.lower(input)

Parameters

TypeNameDescription
stringinputString to be converted

Returns

TypeNameDescription
stringresultAltered string with all uppercase letters converted to lowercase

Examples

Convert an uppercase string to lowercase
local result = string.lower("HELLO")

engine.print("info", result) --'hello'
Convert a mixed-case string to lowercase
local result = string.lower("Hello World")

engine.print("info", result) --'hello world'
Already-lowercase strings are unchanged
local result = string.lower("already lowercase")

engine.print("info", result) --'already lowercase'
Numbers and special characters are unchanged
local result = string.lower("ABC123!@#")

engine.print("info", result) --'abc123!@#'
Perform a case-insensitive comparison
local str1 = "Hello"
local str2 = "HELLO"

if string.lower(str1) == string.lower(str2) then
    engine.print("info", "Strings are equal (case-insensitive)")
end
Normalize user input for comparison
local input = "YES"

if string.lower(input) == "yes" then
    engine.print("info", "User confirmed")
end
Convert table keys to lowercase
local data = {
    Name = "John",
    Age = 25,
    City = "NYC"
}

for key, value in pairs(data) do
    engine.print("info", string.lower(key), value)
end

--[[
Output: 
'name John'
'age 25'
'city NYC'
]]
Normalize an email address to lowercase
local email = "User@Example.COM"
local normalized = string.lower(email)

engine.print("info", normalized) --'user@example.com'
Strings with only numbers are unchanged
local result = string.lower("123456")

engine.print("info", result) --'123456'
Lowercase an empty string
local result = string.lower("")

engine.print("info", result) --''
Chain lowercase with other string functions
local result = string.lower("HELLO WORLD"):gsub(" ", "_")

engine.print("info", result) --'hello_world'

On this page