[tokenizer/string_algo] splitting after a sequence
Hi. I need to tokenize a string according to a delimiter sequence, rather than the common "any-of-characters" algorithm. What I mean is that if I'll use the sequence "ab" to split the string "1ab2ab3", I'll get { "1", "2", "3" }, but if I'll use the same "ab" sequence to split a slightly different "1ab2ba3" string, I'll get { "1", "2ba3" }. I've looked at the tokenizer lib and string_algo's split method, but couldn't find any evidence that any of them already contain such a feature. Is there such a thing in Boost? Thanks, Yuval
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Yuval Ronen Sent: Saturday, June 18, 2005 7:19 AM To: boost-users@lists.boost.org Subject: [Boost-users] [tokenizer/string_algo] splitting after a sequence
Hi.
I need to tokenize a string according to a delimiter sequence, rather than the common "any-of-characters" algorithm. What I mean is that if I'll use the sequence "ab" to split the string "1ab2ab3", I'll get { "1", "2", "3" }, but if I'll use the same "ab" sequence to split a slightly different "1ab2ba3" string, I'll get { "1", "2ba3" }.
I've looked at the tokenizer lib and string_algo's split method, but couldn't find any evidence that any of them already contain such a feature. Is there such a thing in Boost?
I haven't used the tokenizer or string_algo libraries, but I know that the Spirit parser library can handle your task: http://www.boost.org/libs/spirit/index.html -- Noah
On Sat, 18 Jun 2005 16:19:10 +0200, Yuval Ronen
Hi.
I need to tokenize a string according to a delimiter sequence, rather than the common "any-of-characters" algorithm. What I mean is that if I'll use the sequence "ab" to split the string "1ab2ab3", I'll get { "1", "2", "3" }, but if I'll use the same "ab" sequence to split a slightly different "1ab2ba3" string, I'll get { "1", "2ba3" }.
I've looked at the tokenizer lib and string_algo's split method, but couldn't find any evidence that any of them already contain such a feature. Is there such a thing in Boost?
You can use split iterators in string_algo: string str = "1ab2ab3"; vector<string> results; typedef boost::split_iteratorstd::string::iterator string_split_iterator; for (string_split_iterator it = make_split_iterator(str, first_finder("ab")); it != string_split_iterator(); ++it) { results.push_back(*it); } -- Be seeing you.
participants (3)
-
Noah Stein
-
Thore Karlsen
-
Yuval Ronen