Q:

Need to extract last figure after dot in a string like "7.8.9.1.5.1.100"

I need to extract last number after last dot in a C++ string like "7.8.9.1.5.1.100" and store it in an integer??
Added:
This string could also be "7.8.9.1.5.1.1" or "7.8.9.1.5.1.0".
I would also like to validate that that its is exactly "7.8.9.1.5.1" before last dot.

A:

std::string has a rfind() method; that will give you the last . From there it's a simple substr() to get the string "100".

A:

const std::string s("7.8.9.1.5.1.100");
const size_t i = s.find_last_of(".");
if(i != std::string::npos)
{
    int a = boost::lexical_cast<int>(s.substr(i+1).c_str());
}

