Lua 字符串分割

lua 字符串分割

function StringTool:stringSplit(str, splitChar)
	local sub_str_tab = {};
	
	while (true) do
		local pos = string.find(str, splitChar);
		if (not pos) then
			local size_t = table.getn(sub_str_tab)
			table.insert(sub_str_tab,size_t+1,str);
			break;
		end
		
		local sub_str = string.sub(str, 1, pos - 1);
		local size_t = table.getn(sub_str_tab)
		table.insert(sub_str_tab,size_t+1,sub_str);
		local t = string.len(str);
		str = string.sub(str, pos + 1, t);
	end
	return sub_str_tab;
end

猜你喜欢

转载自caiwb1990.iteye.com/blog/2382150