在 lua 列表中搜索不完整的项目
search for uncomplete item in lua list
您知道如何在 table 中搜索未完成的项目吗?
items = {"0x10_first_one.json", "0x20_second_one.json", "0xFF_thirs_one.json"}
local function locate( table, value )
for i = 1, #table do
if table[i] == value then
print(i)
return true
end
end
print( value ..' not found' )
return false
end
locate(items, "0x10" )
我知道我需要搜索“0x10_first_one.json”才能返回 1。但我通常没有完整的字符串。我只有“0x10”。我如何搜索它,它也返回 1。
谢谢
Search for an item in a Lua list
我自己找到了解决方案。
function locate(table, value)
for i = 1, #table do
test = tostring(table[i])
if string.match(test, value) ~= nil then
print(i)
end
end
end
locate(t, "0x10[_%w]+.json")
您知道如何在 table 中搜索未完成的项目吗?
items = {"0x10_first_one.json", "0x20_second_one.json", "0xFF_thirs_one.json"}
local function locate( table, value )
for i = 1, #table do
if table[i] == value then
print(i)
return true
end
end
print( value ..' not found' )
return false
end
locate(items, "0x10" )
我知道我需要搜索“0x10_first_one.json”才能返回 1。但我通常没有完整的字符串。我只有“0x10”。我如何搜索它,它也返回 1。
谢谢
Search for an item in a Lua list
我自己找到了解决方案。
function locate(table, value)
for i = 1, #table do
test = tostring(table[i])
if string.match(test, value) ~= nil then
print(i)
end
end
end
locate(t, "0x10[_%w]+.json")