在Lua中将字符串中的所有字符都转换为小写 [英] Making all the characters in a string lowercase in Lua

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

问题描述

这是东西.我正在尝试在Lua中将字符串转换为小写字母,但无法正常工作.我已经做到了

Here is the thing. I am trying to convert a string in lowercase in Lua, but it's not working. I have done this

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.

有什么想法吗?

推荐答案

您是对的,这是实现此目的的方法之一.如果您的"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.

这篇关于在Lua中将字符串中的所有字符都转换为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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