在 Lua 中将字符串中的所有字符变成小写

编程入门 行业动态 更新时间:2024-10-28 12:27:33
本文介绍了在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-03-29 03:51:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/747848.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   中将   字符   Lua

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!