string - Use of ^ and gsub in Lua -
function title case(thestring) return (thestring:gsub("^%a", string.upper):gsub("%s+%a", string.upper)) end
i have above mentioned code. wanted know use of
^
operator in above code. know^
used in sets exclude/negate succeeding values in set since it's not set,^
meant ?why
gsub
used twice in above code? both times, letters being converted upper case! please explain what's happening in above line of code.
^
in beginning of pattern anchor "the beginning of string", i.e,"^%a"
matches"%a"
(a letter) if it's in beginning of string.the first
string.gsub()
make first letter in string uppercase, secondstring.gsub()
make first letter of other words (a letter follows whitespace) uppercase.for instance, string
"hello world"
turns"hello world"
after firststring.gsub()
, turns"hello world"
after secondstring.gsub()
.
Comments
Post a Comment