- --[[
- 提取字符串中的数字
- mode = 0 :提取一串连贯的数字,返回数字
- mode = 1 :提取一组不连贯的数字,返回数组
- ]]--
- function XX.ExtractNum(str,mode)
- mode = mode or 0
- if str == nil then
- return nil
- end
- if mode == 0 then
- return tonumber(string.match(str,"%d+")) or nil
- elseif mode == 1 then
- local rets = {}
- local index = 1
- for word in string.gmatch(str,"%d+") do
- table.insert(rets,index,word)
- index = index + 1
- end
- return rets
- else
- print("XX.ExtractNum:参数mode不正确")
- end
- return nil
- end
复制代码
|