What's the best way to check and see if a string has a given extension (like .bmp) at the end of it and append that extension if it doesn't?
Hi,
It is simple if you use the API "PathAddExtension":
fn PathAddExtension, addr String, ".bmp"
Note:
a.if the String have an extension, no extension is added.
b. If the String no have extension, extension is added.
:-)
Add:
include shlwapi.inc
includelib shlwapi.lib
If you want to remove the extension (if there is...) use "PathRemoveExtension" (invoke PathRemoveExtension,addr String)
Wow, that's great. Thanks.
Hacky way:
- get string length
- check that last four characters = ".bmp"
- if not, append them :wink
Quote from: Robert Bieber on March 28, 2005, 11:18:35 PM
What's the best way to check and see if a string has a given extension (like .bmp) at the end of it and append that extension if it doesn't?
Ahhhh, but what is an extension? "yourfile.bmp.bmp.bmp" is a perfectly legal name, as is "yourfile.areallylongextension", as is "afilenamewithnoextensionatall".
Sorry, couldn't resist going all Zen, "keepin' it real" as Ali G would say :cheekygreen: :eek
Quote from: sluggy on March 29, 2005, 11:10:09 AM
Quote from: Robert Bieber on March 28, 2005, 11:18:35 PM
What's the best way to check and see if a string has a given extension (like .bmp) at the end of it and append that extension if it doesn't?
Ahhhh, but what is an extension? "yourfile.bmp.bmp.bmp" is a perfectly legal name, as is "yourfile.areallylongextension", as is "afilenamewithnoextensionatall".
Sorry, couldn't resist going all Zen, "keepin' it real" as Ali G would say :cheekygreen: :eek
Aaah, but the question is, little grasshopper, whether the file has a particular extension - "blah.bmp.bmp.blah.bmp" is a perfectly legitimate filename, and it ends with ".bmp" which makes it a bmp file (as far as windows is concerned.)
Not every file that ends in .bmp is a bmp format file.
Regards, P1 :8)
Quote from: P1 on March 29, 2005, 03:05:33 PM
Not every file that ends in .bmp is a bmp format file.
That's why I said "(as far as windows is concerned)" :P
Obviously you can't tell until you actually open it and check its format.
Quote
Ahhhh, but what is an extension? "yourfile.bmp.bmp.bmp" is a perfectly legal name, as is "yourfile.areallylongextension", as is "afilenamewithnoextensionatall".
Sluggy, but he can test all .bmp begining at the end until the last «.». Why not ?
I have a telephone in the parlor and another in the bedroom. The one in the bedroom is an extension.
Paul
Hi,
Since it is 4 chars get the last DWORD from the buffer i na register. Do a
cmp eax,'pmb.' ; .bmp in reverse due to intel byte ordering
Thomas
There's also PathRemoveExtension and PathReplaceExtension to prevent duplicated extensions.