首字符大写Lua [英] First character uppercase Lua

查看:342
本文介绍了首字符大写Lua的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Lua是否提供了使单词中的第一个字符变为大写的功能(如php中的ucfirst)?如果是,该如何使用?

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?

我希望keywords[1]是首字母大写.我已经读过string.upper做到了,但是整个单词变成了大写.

I want keywords[1] to be first letter uppercase. I've read that string.upper does it but it made the whole word uppercase.

推荐答案

此处,包括这个.要将字符串中的第一个字符更改为大写,可以使用:

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

这篇关于首字符大写Lua的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆