Lua 中的字符串比较

尝试创建一个字典函数,首先我制作了一个二维表:

dictionary = {}
for i = 1, 52 do
  dictionary[i] = {}
end

然后我从一个txt文件中读取单词到字典表中,该表有26个大写字母条目,同样也有26个小写字母条目。

当我尝试搜索表来比较单词时,我遇到了一些困难:

test = dictionary[1][176]
testTwo = "Ave"

if test == testTwo then print("The strings are the same") else print("They are not the same)
end

我知道在dictionary[1][176]是"Ave",但是当我尝试进行任何比较时,它们将不相等。

作为回答,这是我如何读取字典:

function CreateDictionary()

  io.input("dictionary.txt")
  dictionary = {}
  for line in io.lines() do
    print(type(line))
    table.insert(dictionary, line)
  end
end
点赞
用户1324082
用户1324082

你可能还没有将 dictionary[1][176] 设置为 Ave,因为当我运行这段代码时会得到 The strings are the same

要将它设置为 Ave,你可以这样做:

dictionary[1][176] = "Ave"
2014-03-10 21:41:20