
AMDG Peter Barker wrote:
Hello,
I have the following program:
#include <string>
#include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/finder.hpp>
int main() { std::string str("12.5e");
boost::last_finder(str,boost::is_digit()); // <--- is this sort of right? }
What I'm trying to do is find the last occurence of a digit in my string (and learn a bit more about Boost.StringAlgorithms!). Am I going down the correct route here, and if so would someone be so kind to add to my program to show how I could obtain and output the index? The call operator for last_finder accepts two paramters which has thrown me as I thought the range was defined at construction.
last_finder searches for the substring specified in the constructor, in the string passed to the function call operator. You can use the standard library fairly easily in this case: #include <string> #include <algorithm> #include <iostream> #include <boost/algorithm/string/classification.hpp> int main() { std::string str("12.5e"); std::cout << (std::find_if(str.rbegin(), str.rend(), boost::is_digit()).base() - str.begin() - 1) << std::endl; } In Christ, Steven Watanabe