Boost logo

Boost Users :

Subject: Re: [Boost-users] [string algorithms] finding last digit
From: Peter Barker (newbarker_at_[hidden])
Date: 2008-09-09 12:10:05


On Tue, Sep 9, 2008 at 4:05 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> 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
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

Steven,

Thanks for your explanation and example.

Regards,

Pete


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net