lua 实现tableToString
Posted xshang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lua 实现tableToString相关的知识,希望对你有一定的参考价值。
function tableToString(studentNum) local str = "{ " str = str.."\n" for k, v in pairs(studentNum) do if type(v) ~= "table" then str = str.."[\""..k.."\"]" str = str..":" str = str..v str = str.."," str = str.."\n" else str = str.."[\""..k.."\"]" str = str..":" str = str..tableToString(v) str = str.."," str = str.."\n" end end str = string.sub(str, 1, -3) str = str.."\n" str = str .." }" return str -- print("tableToString===", str) end local studentNum = {1, {6, 7, {"hello", "world"}}, 5} local str = tableToString(studentNum) print(str)
以上是关于lua 实现tableToString的主要内容,如果未能解决你的问题,请参考以下文章