Ok, first of all I don't want to use Boost, or any external libraries. I just want to use the C++ Standard Library. I can easily split strings with a given delimiter with my split()
function:
void split(std::string &string, std::vector<std::string> &tokens, const char &delim) {
std::string ea;
std::stringstream stream(string);
while(getline(stream, ea, delim))
tokens.push_back(ea);
}
I do this on filenames. But there's a problem. There are files that have extensions like: tar.gz
, tar.bz2
, etc. Also there are some filenames that have extra dots. Some.file.name.tar.gz
. I wish to separate Some.file.name
and tar.gz
Note: The number of dots in a filename isn't constant.
I also tried PathFindExtension
but no luck. Is this possible? If so, please enlighten me. Thank you.
Edit: I'm very sorry about not specifying the OS. It's Windows.
I think you could use std::string
find_last_of
to get the index of the last .
, and substr
to cut the string (although the "complex extensions" involving multiple dots will require additional work).
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