lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Shmuel Zeigerman wrote:
Zhe Hu wrote:

I am wondering how to turn "the cat in the hat" into "The Cat In The
Hat" in pure Lua.

string.gsub (s, "(%w+)", function(a) return
  string.upper(string.sub(a,1,1)) .. string.sub(a,2) end)

Yet shorter:

string.gsub (s, "(%w)(%w*)", function(a,b) return
  string.upper(a) .. b end)