mugyu
11/6/2014 - 12:52 AM

lua で path を 分解する

lua で path を 分解する

local segments = {}
local path = '/foo/bar/hoge/piyo'
for segment in string.gmatch(path, "[^/\\]+") do
  table.insert(segments, segment)
end

for _, segment in pairs(segments) do
  print(segment)
end

-- foo
-- bar
-- hoge
-- piyo