简体   繁体   English

第一个字符大写Lua

[英]First character uppercase Lua

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? Lua是否提供了一个函数来使单词中的第一个字符为大写(如php中的ucfirst),如果是,如何使用它?

I want keywords[1] to be first letter uppercase. 我希望keywords[1]是首字母大写。 I've read that string.upper does it but it made the whole word uppercase. 我已经读过string.upper ,但它使整个单词成为大写。

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

这也有效: s:sub(1,1):upper()..s:sub(2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM