Vital.sandbox
String

string.upper

Shared

Converts all lowercase letters to uppercase


Syntax

local result = string.upper(input)

Parameters

TypeNameDescription
stringinputString to be converted

Returns

TypeNameDescription
stringresultAltered string with all uppercase letters converted to uppercase

Examples

Convert a lowercase string to uppercase
local result = string.upper("hello")

engine.print("info", result) --'HELLO'
Convert a mixed-case string to uppercase
local result = string.upper("Hello World")

engine.print("info", result) --'HELLO WORLD'
Already-uppercase strings are unchanged
local result = string.upper("ALREADY UPPERCASE")

engine.print("info", result) --'ALREADY UPPERCASE'
Numbers and special characters are unchanged
local result = string.upper("abc123!@#")

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

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

if string.upper(input) == "YES" then
    engine.print("info", "User confirmed")
end
Create a constant name from a variable name
local varName = "max_value"
local constant = string.upper(varName)

engine.print("info", constant) --'MAX_VALUE'
Emphasize text with uppercase
local text = "warning"
local emphasized = string.upper(text)

engine.print("info", emphasized) --'WARNING'
Convert a status string to an enum value
local status = "active"
local enum = string.upper(status)

engine.print("info", enum) --'ACTIVE'
Strings with only numbers are unchanged
local result = string.upper("123456")

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

engine.print("info", result) --''
Convert a title to an uppercase header
local title = "my document title"
local header = string.upper(title)

engine.print("info", header) --'MY DOCUMENT TITLE'
Convert a column name to SQL-style uppercase
local column = "user_id"

engine.print("info", string.upper(column)) --'USER_ID'
Compare two strings ignoring case
local function equalsIgnoreCase(a, b)
    return string.upper(a) == string.upper(b)
end

engine.print("info", equalsIgnoreCase("Test", "test")) --true
Format a command string in uppercase
local cmd = "help"

engine.print("info", "Command: "..string.upper(cmd)) --'Command: HELP'
Build an acronym from a phrase
local text = "hypertext markup language"
local acronym = ""
for word in string.gmatch(text, "%S+") do
    acronym = acronym..string.upper(string.sub(word, 1, 1))
end

engine.print("info", acronym) --'HML'
Convert to shouty snake case
local name = "my_variable_name"
local shouty = string.upper(name)

engine.print("info", shouty) --'MY_VARIABLE_NAME'

On this page