Lua 判断文件类型为wav

【1】应用示例

文件类型为wav格式

 1 -- 判断文件类型
 2 local function isType(filename) 
 3     local res = string.match(filename, ".%.wav$")
 4     if not res then
 5         return 'is no.'
 6     else
 7         return 'is ok.'
 8     end
 9 end
10 
11 -- test
12 print(isType('123.wav'))   -- is ok.
13 print(isType('456wav'))    -- is no.
14 print(isType('wav'))       -- is no.
15 print(isType('.wav.xml'))  -- is no.
16 print(isType('test.wav'))  -- is ok.
17 print(isType('.wav.wav'))  -- is ok.

如上,判断文件类型。

【2】总结

Lua 模式匹配

Good Good Study, Day Day Up.

顺序  选择  循环 总结

猜你喜欢

转载自www.cnblogs.com/Braveliu/p/10695661.html