Lua 拆分字符

lua 拆分字符

function StringTool:split( str_, limit_, type_ )
	if str_ == nil or str_ == "" then
		LogInfo("StringTool:split wrong string")
		return nil
	end
	if limit_ == nil or limit_ == "" then
		LogInfo("StringTool:split wrong limit")
		return nil
	end
	local pos = 0
	local valueTbl = {}
	while pos ~= nil do
		local value
		local _next = string.find(str_, limit_, pos + 1)
		if _next ~= nil then
			value = string.sub(str_, pos + 1, _next - 1)
		elseif pos ~= string.len(str_) then
			value = string.sub(str_, pos + 1, string.len(str_))
		end
		if value then
			if type_ == "int" then
				value = tonumber(value)
			end
			table.insert(valueTbl, value)
		end
		pos = _next
	end
	return valueTbl
end

猜你喜欢

转载自caiwb1990.iteye.com/blog/2382151
LUA
今日推荐