Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First character uppercase Lua

Tags:

string

lua

Does Lua provide a function to make the first character in a word uppercase (like ucfirst in php) and if so, how to use it?

I want keywords[1] to be first letter uppercase. I've read that string.upper does it but it made the whole word uppercase.

like image 364
Tomek Avatar asked Mar 11 '10 00:03

Tomek


People also ask

How do you capitalize in Lua?

Converting a string to its uppercase in Lua is done by the string. upper() function.

How to lowercase string in Lua?

Converting a string to its lowercase in Lua is done by the string. lower() function.

How to convert string to upper and lower?

Java String toUpperCase() Method The toUpperCase() method converts a string to upper case letters. Note: The toLowerCase() method converts a string to lower case letters.

What function are used to convert uppercase and lowercase in string?

Use string. upper() to convert a string to uppercase, and string. lower() to convert a string to lowercase.


1 Answers

There are some useful string recipes here, including this one. To change the first character in a string to uppercase, you can use:

function firstToUpper(str)
    return (str:gsub("^%l", string.upper))
end
like image 93
interjay Avatar answered Sep 20 '22 12:09

interjay