.upper()

rhysfirkins's avatar
Published Sep 6, 2023
Contribute to Docs

The .upper() function converts a string to uppercase.

Syntax

string.upper(string)

The .upper() function will convert all letters of a specified string to uppercase. Numbers and punctuation will remain unaffected.

Example

The example below shows how .upper() takes a string with both upper and lower case letters and returns it in uppercase.

Note: The .upper() function creates a copy of the specified string to modify, leaving the original unchanged.

myString = "Bang!"
print(myString)
print(string.upper(myString))
print(myString)

This code will display the following output:

Bang!
BANG!
Bang!

All contributors

Contribute to Docs

Learn Lua on Codecademy