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.
Converting a string to its uppercase in Lua is done by the string. upper() function.
Converting a string to its lowercase in Lua is done by the string. lower() function.
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.
Use string. upper() to convert a string to uppercase, and string. lower() to convert a string to lowercase.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With