js默认事件汇总
360 2023-04-03 01:58:12
很多时候我们需要从全路径中取得目录,文件名或者扩展名。办法有许多,看lua是怎么做的:
–获取路径
function stripfilename(filename)
return string.match(filename, “(.+)/[^/]*%.%w+$”) — *nix system
–return string.match(filename, “(.+)[^]*%.%w+$”) — windows
end
–获取文件名
function strippath(filename)
return string.match(filename, “.+/([^/]*%.%w+)$”) — *nix system
–return string.match(filename, “.+([^]*%.%w+)$”) — *nix system
end
–去除扩展名
function stripextension(filename)
local idx = filename:match(“.+()%.%w+$”)
if(idx) then
return filename:sub(1, idx-1)
else
return filename
end
end
–获取扩展名
function getextension(filename)
return filename:match(“.+%.(%w+)$”)
end
refer to: http://lua-users.org/lists/lua-l/2010-07/msg00088.html