The Artima Developer Community
Sponsored Link

Python Buzz Forum
Incrementing strings

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Simon Brunning

Posts: 679
Nickname: simonb
Registered: Jul, 2003

Simon Brunning is keen on Python. And uses Java rather a lot.
Incrementing strings Posted: Mar 9, 2005 6:29 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Simon Brunning.
Original Post: Incrementing strings
Feed Title: Small Values of Cool
Feed URL: http://www.brunningonline.net/simon/blog/index-PnJ.xml
Feed Description: Simon Brunning - stuff that I find interesting
Latest Python Buzz Posts
Latest Python Buzz Posts by Simon Brunning
Latest Posts From Small Values of Cool

Advertisement
While I'm posting silly little Python scripts, here's one I prepared earlier. def inc_string(string, allowGrowth=True):     '''Increment a string.'''     CHAR_RANGES = [                    Bunch(from_char=48, to_char=57),  # digits                    Bunch(from_char=65, to_char=90),  # upper case                    Bunch(from_char=97, to_char=122), # lower case                   ]     string_chars = list(string)     string_chars[-1] = chr(ord(string_chars[-1]) + 1)     for index in range(-1, -len(string_chars), -1):         for char_range in CHAR_RANGES:             if ord(string_chars[index]) == char_range.to_char + 1:                 string_chars[index] = chr(char_range.from_char)                 string_chars[index-1] = chr(ord(string_chars[index-1]) + 1)     for char_range in CHAR_RANGES:         if ord(string_chars[0]) == char_range.to_char + 1:             if allowGrowth:                 string_chars[0] = chr(char_range.from_char)...

Read: Incrementing strings

Topic: intermission Previous Topic   Next Topic Topic: Unfinished Business I: Quick and Dirty Remote Objects

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use