Help me with file formats, how can I detect for example .bmp ending filename?
Other can I do, but the endings are problems.
Sorry for bad english
Help me! file formats
Started by Konlab, May 16 2014 04:47 PM
11 replies to this topic
#1
Posted 16 May 2014 - 04:47 PM
#2
Posted 16 May 2014 - 07:20 PM
Assuming you already have the filename:
function getExtension(filename)
if filename:find("$.+(%..+)^") then
local a,b,c = filename:find("$.+(%..+)^")
return c
end
end
#3
Posted 16 May 2014 - 07:58 PM
Sorry, I don't understand anything.
Please tell me what line what does.
Please tell me what line what does.
#5
Posted 16 May 2014 - 08:01 PM
And why $.+(%..+)
.?
.?
#7
Posted 16 May 2014 - 08:05 PM
Uh
if IDon'tUnderstandAnything() then
print("go away")
else
print("stay here")
end
Output:
go away
if IDon'tUnderstandAnything() then
print("go away")
else
print("stay here")
end
Output:
go away
#8
Posted 16 May 2014 - 08:42 PM
Alright. I'll break it down:
The ": starts a string, as patterns are strings.
The $: means that the string must START with the following pattern
The .: matches any character
The +: allows the previous case to be repeated (match any characters.
The %.: matches for a REAL period
The (: starts a capture (an additional return value if the containing case was matched)
The .+ again, matches all characters
The ): closes the capture
The ^: means the string must END with this pattern.
In short it looks for something like this:
(Any text).(any text) and returns the second set of parenthasees's contents.
The ": starts a string, as patterns are strings.
The $: means that the string must START with the following pattern
The .: matches any character
The +: allows the previous case to be repeated (match any characters.
The %.: matches for a REAL period
The (: starts a capture (an additional return value if the containing case was matched)
The .+ again, matches all characters
The ): closes the capture
The ^: means the string must END with this pattern.
In short it looks for something like this:
(Any text).(any text) and returns the second set of parenthasees's contents.
#9
Posted 16 May 2014 - 08:56 PM
apemanzilla, on 16 May 2014 - 08:42 PM, said:
The $: means that the string must START with the following pattern.
The ^: means the string must END with this pattern.
The ^: means the string must END with this pattern.
Your code could also be shortened to a one-liner:
function getExtension(filename)
return filename:match("^.+(%..+)$")
end
#10
Posted 17 May 2014 - 05:56 AM
And what is filename:find
#11
Posted 17 May 2014 - 01:10 PM
Konlab, on 17 May 2014 - 05:56 AM, said:
And what is filename:find
#12
Posted 17 May 2014 - 11:45 PM
You need to stop complaining about our answers and read up on lua.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











