local function remove_assign_char(sourceStr, removeStr)
local curSubStrTbl = {}
--01,以特定字符分离生成对应表
while true do
local curSubStrPos = string.find(sourceStr, removeStr)
if not curSubStrPos then
curSubStrTbl[#curSubStrTbl + 1] = sourceStr
break
end
local tmpSubStr = string.sub(sourceStr,1,curSubStrPos-1)
curSubStrTbl[#curSubStrTbl+1] = tmpSubStr
sourceStr = string.sub(sourceStr, curSubStrPos+1, #sourceStr)
end
--02,拼接
local toMergeStr =""
local split_count = 1
while true do
if curSubStrTbl[split_count] then
toMergeStr = toMergeStr .. curSubStrTbl[split_count]
split_count = split_count + 1
else
break
end
end
return toMergeStr
end
local test_str = "1, 2, 3"
local assign_str = remove_assign_char(test_str, " ")
local convert_tbl = {'[^,]+', function(w) table.insert(convert_tbl, tonumber(w)) end}
输出如下:
for _, var in pairs(convert_tbl) do print(_, var)end