string 在 Lua 中将字符串中的所有字符变成小写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3202531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making all the characters in a string lowercase in Lua
提问by OddCore
Here is the thing. I am trying to convert a string in lowercase in Lua, but it's not working. I have done this
这是事情。我正在尝试在 Lua 中将字符串转换为小写,但它不起作用。我已经这样做了
String = String:lower()
but it doesn't like it. I am sure that is the way to do it, I've seen it done before. A few sites suggest it might be a problem caused by a wrong version of the interpreter.
但它不喜欢它。我相信这是这样做的方法,我以前见过它。一些站点表明这可能是由错误版本的解释器引起的问题。
Any ideas?
有任何想法吗?
回答by Hendrik
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)
But its really the same as doing
但它真的和做一样
myString = myString:lower()
assuming that myString is actually a string, however.
然而,假设 myString 实际上是一个字符串。
The "long" version has one advantage, it actually works if myString is a number, while the second one errors in that case.
“长”版本有一个优点,如果 myString 是数字,它实际上可以工作,而在这种情况下第二个错误。