【1】应用示例
文件类型为wav格式
-- 判断文件类型
local function isType(filename)
local res = string.match(filename, ".%.wav$")
if not res then
return 'is no.'
else
return 'is ok.'
end
end -- test
print(isType('123.wav')) -- is ok.
print(isType('456wav')) -- is no.
print(isType('wav')) -- is no.
print(isType('.wav.xml')) -- is no.
print(isType('test.wav')) -- is ok.
print(isType('.wav.wav')) -- is ok.
如上,判断文件类型。
【2】总结
Lua 模式匹配
Good Good Study, Day Day Up.
顺序 选择 循环 总结