我正在尝试将文本文件中的特定行存储到变量中。
file = io.open("words.lua", "r")
randLine = math.random(1, 109583)
local n = 0
for l in io.lines("words.lua") do
n = n + 1
if n == randLine then
word = randLine
end
end
我想将字符串存储在randLine
的{{1}}上。我怎么能这样做?
答案 0 :(得分:0)
lines是一个返回行的迭代器,而不是行号。
file = io.open("words.lua", "r")
randLine = math.random(1, 109583)
local n = 0
for line in file:lines() do
n = n + 1
if n == randLine then
word = line
end
end
file:close()