[string algorithms] finding last digit
Hello,
I have the following program:
#include <string>
#include
AMDG Peter Barker wrote:
Hello,
I have the following program:
#include <string>
#include
#include 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
On Tue, Sep 9, 2008 at 4:05 PM, Steven Watanabe
AMDG
Peter Barker wrote:
Hello,
I have the following program:
#include <string>
#include
#include 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
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
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Steven, Thanks for your explanation and example. Regards, Pete
participants (2)
-
Peter Barker
-
Steven Watanabe