Menu
Coddy logo textTech

string.upper & string.lower

Part of the Fundamentals section of Coddy's Lua journey — lesson 45 of 90.

string.upper() and string.lower().

These functions allow you to convert strings to different cases. The string.upper() function converts all letters in a string to uppercase, while string.lower() converts them to lowercase:

local message = "Hello World"
local uppercase = string.upper(message)
local lowercase = string.lower(message)

print(uppercase)  -- outputs: HELLO WORLD
print(lowercase)  -- outputs: hello world

These functions are particularly useful for standardizing user input or creating consistent formatting in your programs. For example, you might convert usernames to lowercase for comparison, or convert headings to uppercase for display purposes.

challenge icon

Challenge

Easy

Create a text formatting system that converts a mixed-case company name to both uppercase and lowercase versions for different display purposes. Declare a variable called companyName and assign it the value "TechCorp Solutions". Use string.upper() to create an uppercase version and store it in a variable called upperName. Use string.lower() to create a lowercase version and store it in a variable called lowerName. Print both the uppercase and lowercase versions on separate lines.

Cheat sheet

Use string.upper() to convert strings to uppercase and string.lower() to convert strings to lowercase:

local message = "Hello World"
local uppercase = string.upper(message)
local lowercase = string.lower(message)

print(uppercase)  -- outputs: HELLO WORLD
print(lowercase)  -- outputs: hello world

These functions are useful for standardizing user input or creating consistent formatting in programs.

Try it yourself

-- Declare the company name variable
companyName = "TechCorp Solutions"

-- TODO: Write your code here to create uppercase and lowercase versions

-- Print the results
print(upperName)
print(lowerName)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals