且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Lua中将字符串中的所有字符都转换为小写

更新时间:2023-02-21 19:43:45

您是对的,这是实现此目的的方法之一.如果您的"String"变量不是字符串,它只会起作用并抛出错误.

You're right, this is one of the ways to do it. It would only not work and throw errors if your "String" variable is not a string.

我个人通常更喜欢使用类似的东西.

Personally, i usually prefer to use something like..

myString = string.lower(myString)

但实际上和做的一样

myString = myString:lower()

但是,假设myString实际上是一个字符串.

assuming that myString is actually a string, however.

"long"版本具有一个优点,如果myString是数字,则它实际上可以工作,而第二个则在这种情况下会出错.

The "long" version has one advantage, it actually works if myString is a number, while the second one errors in that case.