[Tutor] what is the equivalent function to strtok() in c++

Alan Gauld alan.gauld at btinternet.com
Mon Jan 11 10:07:23 CET 2010


"Dave Angel" <davea at ieee.org> wrote 

> If your tokens are separated by whitespace, you can simply use a single 
> call to split().  It will turn a single string into a list of tokens.
> 
> line = "Now   is the time"
> print line.split()
> 
> will display the list:
> ['Now', 'is', 'the', 'time']

And if it's not separated by whitespace you can supply the 
separator, eg a colon:

line.split(':')

For more sophisticated functionality use the re module or a 
specialised parser.


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list