Jump to content




Help me! file formats


  • You cannot reply to this topic
11 replies to this topic

#1 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 16 May 2014 - 04:47 PM

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

#2 apemanzilla

  • Members
  • 1,421 posts

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 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 16 May 2014 - 07:58 PM

Sorry, I don't understand anything.
Please tell me what line what does.


#4 Agoldfish

  • Members
  • 451 posts
  • LocationSome Fish Bowl in Ohio.

Posted 16 May 2014 - 07:59 PM

View PostKonlab, on 16 May 2014 - 07:58 PM, said:

Sorry, I don't understand anything.
Please tell me what line what does.
It detects everything after a period in a file name.

#5 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 16 May 2014 - 08:01 PM

And why $.+(%..+)
.?

#6 Lignum

  • Members
  • 558 posts

Posted 16 May 2014 - 08:02 PM

View PostKonlab, on 16 May 2014 - 08:01 PM, said:

And why $.+(%..+)
.?
It's a pattern.

#7 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 16 May 2014 - 08:05 PM

Uh
if IDon'tUnderstandAnything() then
print("go away")
else
print("stay here")
end
Output:
go away

#8 apemanzilla

  • Members
  • 1,421 posts

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.

#9 Lignum

  • Members
  • 558 posts

Posted 16 May 2014 - 08:56 PM

View Postapemanzilla, 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.
Are you sure it's not the other way around? Because your code only seems to work for me when I swap the two.

Your code could also be shortened to a one-liner:
function getExtension(filename)
  return filename:match("^.+(%..+)$")
end


#10 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 17 May 2014 - 05:56 AM

And what is filename:find

#11 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 17 May 2014 - 01:10 PM

View PostKonlab, on 17 May 2014 - 05:56 AM, said:

And what is filename:find
http://lua-users.org...LibraryTutorial

#12 TyDoesMC

  • Members
  • 154 posts
  • LocationEarth

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