lua 字符串分隔,支持以单个字符或字符串进行分隔

    1. local function explode ( _str, seperator)
      local pos, arr = 0, {}
      for st, sp in function() return string.find( _str, seperator, pos, true ) end do
      table.insert(arr, string.sub(_str, pos, st-1 ))
      pos = sp + 1
      end
      table.insert(arr, string.sub( _str, pos))
      return arr
      end

    2. local ta2 = explode("hsee_,sdj_,ehi_,djsd","_,")
      local newSt2 = table.concat(ta2,"\n")
      print(newSt2)

posted @ 2018-10-09 23:06  阿拉善的樵夫  阅读(342)  评论(0编辑  收藏  举报