Monster_List = {'Hunter','creature','demon'}
Monster_List = Monster_List:lower()那呢?
Attacks = {}
Attacks[1] = {'CreaTurE','MonstEr'}
Attacks[2] = {'FrOG', 'TurtLE'}如果这看起来太蠢了,我很抱歉,但是我怎么把桌子的所有内容都小写呢?
编辑:至于第二个问题,我是这样做的,不确定是否正确。
for i=1,#Attacks do
for k,v in pairs(Attacks[i]) do
Attacks[i][k] = v:lower()
end
end发布于 2014-05-01 19:47:12
迭代表并更新值。
lst = {'BIRD', 'Frog', 'cat', 'mOUSe'}
for k,v in pairs(lst) do
lst[k] = v:lower()
end
table.foreach(lst, print)产生的结果:
1 bird
2 frog
3 cat
4 mouse要处理嵌套表,递归函数将使其变得轻而易举。像这样吗?
lst = {
{"Frog", "CAT"},
{"asdf", "mOUSe"}
}
function recursiveAction(tbl, action)
for k,v in pairs(tbl) do
if ('table' == type(v)) then
recursiveAction(v, action)
else
tbl[k] = action(v)
end
end
end
recursiveAction(lst, function(i) return i:lower() end)
-- just a dirty way of printing the values for this specific lst
table.foreach(lst, function(i,v) table.foreach(v, print) end)产生的结果:
1 frog
2 cat
1 asdf
2 mousehttps://stackoverflow.com/questions/23415300
复制相似问题