--[[--
从表格中删除指定值,返回删除的值的个数
array 数组
value 数组中目标值
removeall 是否都删除(如果不传则默认只删除第一个匹配的值)
local array = {"a", "b", "c", "c"}
print(table.removebyvalue(array, "c", true)) -- 输出 2
]]
function table.removebyvalue(array, value, removeall)
local c, i, max = 0, 1, #array
while i <= max do
if array[i] == value then
table.remove(array, i)
c = c + 1
i = i - 1
max = max - 1
if not removeall then break end
end
i = i + 1
end
return c
end
lua删除表中多个相同的元素
最新推荐文章于 2024-04-17 18:26:58 发布