views:

181

answers:

2

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.

+4  A: 

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
interjay
Thanks! Works great
Tomek
+3  A: 

This also works: s:sub(1,1):upper()..s:sub(2)

lhf