equiv from python

Ignacio Vazquez-Abrams ignacio at openservices.net
Tue Aug 28 17:54:55 EDT 2001


On 28 Aug 2001, Dan Stromberg wrote:

> Does c++ have an equivalent to this from python:
>
> >>> import string
> >>> s='ab:cd:efg:ghi:'
> >>> print string.splitfields(s,':')
> ['ab', 'cd', 'efg', 'ghi', '']
>
> IE, can the standard c++ library take a string, split it up on a
> particular separator character, and return the corresponding list of
> strings?
>
> I know I can write something to do this, but I'd rather learn how to
> use the STL or similar, if applicable.

Not with string per se, but you can do it by using for_each() on a
vector<char> and adding the vector<char> chunk to a list<vector<char> > when
you encounter a colon.

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list