I was wondering is it really necessary to use string algorithms to find in 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. 2.) How would I do this using string algorithm instead.
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_rangestring::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.
participants (2)
-
chun ping wang
-
Pavol Droba