- function XX.SplitEx(Str, cutSymbol)
-
- cutSymbol = tostring(cutSymbol)
- if (cutSymbol=='') then
- return {}
- end
-
- cutSymbol = XM.Split(cutSymbol,"|")
- local result = Str
- local new = {}
- for i=1,#cutSymbol do
- local s = cutSymbol[i]
- if type(result) == "string" then
- result = XM.Split(Str,s)
- elseif type(result) == "table" then
- for _,v in pairs(result) do
- local x = XM.Split(v,s)
- if x and type(x) == "table" then
- for _,val in pairs(x) do
- table.insert(new,#new+1,val)
- end
- end
- end
- result = XM.ArrayAssign(new)
- new = {}
- end
- end
-
- return result
- end
复制代码 使用示例:
local str = "a,b-c,d-e"
local ret = XX.SplitEx(str,",|-") --以,和-作为分隔符
print(ret)
--运行结果: {"a","b","c","d","e"}
使用场景: 脚本界面用户需要用户输入需要英文逗号分割时,
用户错填成了中文逗号,导致脚本报错,可以使用扩展分割进行
同时处理两种语言分隔符
|