码迷,mamicode.com
首页 > 其他好文 > 详细

lua 实现tableToString

时间:2017-11-04 16:33:38      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:string   ble   pairs   turn   function   class   end   ring   table   

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

标签:string   ble   pairs   turn   function   class   end   ring   table   

原文地址:http://www.cnblogs.com/xshang/p/7783290.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!