Garry's Mod Wiki

string.lower

string string.lower( string str )

Description

Changes any upper-case letters in a string to lower-case letters.

Arguments

1 string str
The string to convert.

Returns

1 string
The original string, with all uppercase letters replaced with their lowercase variants.

Example

Demonstrates the use of this function.

print( string.lower( "ABCDEFG" ) ) print( string.lower( "AbCdefG" ) ) print( string.lower( "abcdefg" ) ) print( string.lower( "1234567890" ) )
Output:
abcdefg abcdefg abcdefg 1234567890

Example

Demonstrates a common use for string.lower - case-insensitive user input.

-- All keys in this table must be lowercase: local products = {} products.apple = "Buy an apple!" products.banana = "Buy a bunch of bananas!" products.tomato = "There's also tomatoes." -- This function is case-insensitive, meaning "APPLE", "apple", and "APPle" are all the same. function GetProduct(userinput) return userinput, products[string.lower(userinput)] end -- Demonstration: print(GetProduct("apple")) print(GetProduct("Apple")) print(GetProduct("APPLE")) print() print(GetProduct("banana")) print(GetProduct("BaNaNa"))
Output:
apple Buy an apple! Apple Buy an apple! APPLE Buy an apple! banana Buy a bunch of bananas! BaNaNa Buy a bunch of bananas!

Page Links


Special Pages


Wikis

?

Render Time: 38ms

DB GetPage 4
Generate Html 10
SaveChanges (1) 9
Render Body 0
Render Sidebar 12