在 Lua 中将字符串中的所有字符变成小写 [英] Making all the characters in a string lowercase in Lua

查看:87
本文介绍了在 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.

长"版本有一个优点,如果 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天全站免登陆