[Tutor] string delimiters

Alan Gauld alan.gauld at btinternet.com
Wed Jun 3 21:53:14 CEST 2015


On 03/06/15 20:10, richard kappler wrote:
> for formatting a string and adding descriptors:
>
> test = 'datetimepart1part2part3the_rest'

If this is really about parsing dates and times have
you looked at the datetime module and its parsing/formatting
functions (ie strptime/strftime)?

> Can I stop using position numbers and start looking for specific characters
> (the delimiter)  and proceed to the end (which is always a constant string
> btw).

The general answer is probably to look at regular expressions.
But they get messy fast so usually I'd suggest trying regular
string searches/replaces and  splits first.

But if your pattern is genuinely complex and variable then
regex may be the right solution.

But if its dates check the strptime() functions first.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list