Can I use a string as a delimiter when using the split method?

I am trying to parse an HTML string using the split method from boost. Can it be used with a line separator, for example "<td>"

? Can anyone give me an example on how to do this efficiently?

I am trying to do something like

vector <string> fields;
split( fields, str,  is_any_of( "<td>" ) );


But then I realize that it treats '<', 't', 'd' and '>' - all characters as delims. I'm trying to find a way to use the string as delim.


source to share

1 answer

Taking a look at the documentation for split

, it works one by one, treating the string as a sequence of characters. Therefore, the predicate it uses to determine if something is a delimiter can only test one character, so if you want to split across a full string, you need to use something else. Of course a regex library could do this, but you could easily link your code by searching for substrings.



All Articles