Luaは中国語の文字列をカットして、指定の文字によって、文字列をカットします


<pre name="code" class="javascript"><pre name="code" class="plain">function LuaSplit(str, split_char)
    if str == "" or str == nil then 
        return {};
    end
	local split_len = string.len(split_char)
    local sub_str_tab = {};
    local i = 0;
    local j = 0;
    while true do
        j = string.find(str, split_char,i+split_len);--    str i+split_len          
        if string.len(str) == i then 
            break;
        end


        if j == nil then
            table.insert(sub_str_tab,string.sub(str,i));
            break;
        end;


        table.insert(sub_str_tab,string.sub(str,i,j-1));
        i = j+split_len;
    end
    return sub_str_tab;
end


local s = LuaSplit("  ,  ,   ,  ",",")
local i = 1
while true  do
    if s[i] then
        print(s[i])
        i = i+1
    else 
        break
    end
end