Created
January 12, 2025 20:36
-
-
Save EncodeTheCode/8a1ad4eec0c6dd5bec8e83a2cf45ecfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <algorithm> | |
bool hasPngExtension(const std::string& filename) { | |
size_t dotPos = filename.rfind('.'); | |
if (dotPos == std::string::npos) return false; | |
std::string extension = filename.substr(dotPos + 1); | |
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); | |
return extension == "png"; | |
} | |
int main() { | |
std::cout << std::boolalpha | |
<< "File: image.png, Has .png: " << hasPngExtension("image.png") << '\n' | |
<< "File: image.PNG, Has .png: " << hasPngExtension("image.PNG") << '\n' | |
<< "File: document.pdf, Has .png: " << hasPngExtension("document.pdf") << '\n' | |
<< "File: no_extension, Has .png: " << hasPngExtension("no_extension") << '\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment