扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

lua怎么判断字符串相等

扬州沐宇科技
2024-01-12 00:27:59
Lua

在Lua中,可以使用==操作符来判断两个字符串是否相等。例如:

local str1 = "hello"
local str2 = "world"

if str1 == str2 then
  print("字符串相等")
else
  print("字符串不相等")
end

输出结果是"字符串不相等",因为str1和str2的值不相等。

此外,Lua中还提供了string库中的函数来进行字符串比较,例如使用string.compare函数:

local str1 = "hello"
local str2 = "world"

if string.compare(str1, str2) == 0 then
  print("字符串相等")
else
  print("字符串不相等")
end

这段代码同样输出"字符串不相等"。

扫码添加客服微信