[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppStripExtension
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppStripExtension
(C++) How do I remove a filename's extension?
std::string stripExtension(const std::string& fileName) { const int length = fileName.length(); for (int i=0; i!=length; ++i) { if (fileName[i]=='.') { return fileName.substr(0,i); } } return fileName; } int main() { assert(stripExtension("Test.txt")=="test"); }
- include <string>
- include <cassert>
Other code snippets
Code links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
