"Increment numbers in a string"

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442460

20th of October 2005

I've just uploaded my second Python Cookbook recipe. It's unfortunately not rocket science but it's application is potentially very useful. With this little function you can generate the next number in a string that contains at least one number.

The mini unittest is quite interesting perhaps:

 $ python increment_strings.py
 from 10dsc_0010.jpg to 10dsc_0011.jpg
 from dsc_9.jpg to dsc_10.jpg
 from 0000001.exe to 0000002.exe
 from ref-04851 to ref-04852



Comment

Show all 2 comments
 
Name:
Email:
hide my email address.

Your email address will be encoded to prevent email-extraction spiders from reading it so you won't get spammed if you decide to show your email address.