Given a string "filename.conf"
, how to I verify the extension part?
I need a cross platform solution.
To extract filename from the file, we use “GetFileName()” method of “Path” class. This method is used to get the file name and extension of the specified path string. The returned value is null if the file path is null. Syntax: public static string GetFileName (string path);
A file saved with c file extension is a source code file written in C programming language. The C file include all the implementation of application's functionality in the form of source code. The declaration of the source code is written in the header files that are saved with . h extension.
Is this too simple of a solution?
#include <iostream> #include <string> int main() { std::string fn = "filename.conf"; if(fn.substr(fn.find_last_of(".") + 1) == "conf") { std::cout << "Yes..." << std::endl; } else { std::cout << "No..." << std::endl; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With