Lua 中去除空格并返回关键词

我需要在字符串中去除空格并且对于每个空格之间的单词返回关键词表 我试过自己的代码但是并不完美

string ="happy halloween day"

local function trimSpace(value)
   if value then
     local tags={}
     i=0
     for c in value:gmatch("%s") do
       i= i + 1
       local c = value:sub(i,i)
      tags[#tags+1] = {"tag" = c}
      end
     return tags
   end
end

local tag = trimSpace(string)
点赞
用户7504558
用户7504558

这个函数使用空格作为分隔符来 "split":

local s = "happy halloween day"
local function Split(s)
    local t ={}
    for word in s:gmatch("([^%s]+)") do
         t[#t+1] = {["tag"] =  word }
    end
    return t
end

local tags =Split(s)
for k,v in pairs(tags) do
   print(k,v.tag)
end
2017-10-31 10:20:29