|
Boost Users : |
From: Pavol Droba (droba_at_[hidden])
Date: 2007-08-01 03:27:39
Hi,
chun ping wang wrote:
> I was wondering is it really necessary to use string algorithms to find in
>
I think, that meaning of the term 'necessary' is quite varying. There is
nothing that forces you to use Boost.StringAlgo if you don't need it.
> variable str2 the last occurence that does not contain a number between
> 1 and 9 and create a substr base on that.
> regulary i would use std::string strNew =
> str2.substr(str2.find_last_not_of("123456789"));
>
> So 2 questions.
>
> 1.) Whats the benefit of the string algorithm version of boost in this case.
Probably none. If your solution suits you well, there is no reason to
use an additional library.
> 2.) How would I do this using string algorithm instead.
>
Since there is no direct find_last_not_of equivalent in the library, the
solution will be probably more complicated than yours.
Here is one solution, that popped in my mind:
using namespace boost;
using namespace std;
iterator_range<string::reverse_iterator> res=
find_token(
make_range(str2.rbegin(), str2.rend()),
!is_digit());
string str_res(res.end().base(), res.begin().base());
(this might not work, I have not tested it).
Best Regards,
Pavol.
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