Created
May 17, 2014 03:45
-
-
Save kinoshita-lab/0f48b55b729806ca2c87 to your computer and use it in GitHub Desktop.
remove file extension from a filename
This file contains hidden or 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
std::string removeExtension(const std::string& fileName) | |
{ | |
std::string r = fileName; | |
const size_t dotIndex = r.rfind("."); | |
if (dotIndex == std::string::npos) { | |
return fileName; | |
} | |
std::string::const_iterator it = r.begin() + dotIndex; | |
if (r.end() == it) { | |
return fileName; | |
} | |
r.erase(it, r.end()); | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment