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 - gsubused 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, second- string.gsub()make first letter of other words (a letter follows whitespace) uppercase.- for instance, string - "hello world"turns- "hello world"after first- string.gsub(), turns- "hello world"after second- string.gsub().
Comments
Post a Comment