Lua笔记:Lua字符串分隔方法


	--------------------------- Lua字符串分隔方法 -----------------------------------------
	--字符串分隔方法
	function string:split(sep)
		local sep, fields = sep or ":", {}
		local pattern = string.format("([^%s]+)", sep)
		self:gsub(pattern, function (c) fields[#fields + 1] = c end)
		return fields
	end
	
	--使用说明
	local num = 0
	local str = "1#2#3"
	local result = str:split("#")  --分隔字符串
    num = #result                  --字符串分隔个数
	--------------------------- Lua字符串分隔方法 -----------------------------------------
	
	--------------------------- Lua拼接字符串 -----------------------------------------
	local imgName = "img"
	local fileName = string.format("%s.png", imgName)
	--------------------------- Lua拼接字符串 -----------------------------------------


你可能感兴趣的:(Cocos2d-x,v3.x,Lua)