Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Incrementing Alpha ID's
Message
De
06/04/2007 10:55:44
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01212864
Message ID:
01212972
Vues:
19
>So, is that something like the following?
>
>lcID="aaaaa"
>lnID=ASC(lcID) + 1
>
>>You just increment it by 1 , each time. When it becomes greater than a "z" you set it back to an "a" and increment the character to the left.

Sort of, but you would do this for the last character (asc() works with the first letter of a string), and then carry over to the previous character.

First with numbers, to understand the principle:
105
+ 1
===
106

199
+ 1
===
200
Note that in the first example, I only added one to the last digit. In the second example, I exceeded the range (0..9), so I had to set it back to zero, and add one to the previous digit. Since this was also already 9, I had to repeat the procedure of carry-over.

Similar for letters. If you want only lowercase letters (a..z), you continue adding one at a time, until you get to "z". After that, you have to restart to "a" (the equivalent of zero in the numeric example), and add one to the previous character.

Note also that the resulting string can become longer than the original:
 99
 +1
 ==
100

zzz
+ 1
===
What? aaaa? or baaa?
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform