Skip to content

Instantly share code, notes, and snippets.

@kinoshita-lab
Created May 17, 2014 03:45
Show Gist options
  • Save kinoshita-lab/0f48b55b729806ca2c87 to your computer and use it in GitHub Desktop.
Save kinoshita-lab/0f48b55b729806ca2c87 to your computer and use it in GitHub Desktop.
remove file extension from a filename
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