lua 字符串比较

创建日期: 2025-01-08 15:46 | 作者: 风波 | 浏览次数: 28 | 分类: openresty

来源:https://www.yisu.com/ask/14177689.html

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

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

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

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

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

if string.compare(str1, str2) == 0 then
  print("字符串相等")
else
  print("字符串不相等")
end
28 浏览
14 爬虫
0 评论