LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Surely there must be a better way of doing this: Integer to Alphabet conversion

I'm writing a program that generates a large number of report files. Many of them might have the same initial filename, so I need to append a character (A, B, C, D, etc) to the end of the filename so that each name is unique.

 

It's easy enough to use a while loop and check if a filename already exists, increment the suffix as needed and arrive at the first unused name.  To comply with our current systems, the suffix has to be an upper case letter. (Using an integer would make this much easier.)

 

So what I need is a function that maps integers to uppercase letters such as: 0->A, 1->B, 2->C...26->AA, 27->AB, 28->AC, etc.

 

The attached code works, but it really seems to me there would be an easier way of doing this.

 

Any ideas?Integer to alphabet.jpg

0 Kudos
Message 1 of 6
(2,609 Views)

Action Engine to the rescue

 

Gen Alpha.png

 

Harder than it looks.

 

I usually prepend the reports name with Date and Time as YYJJJHHMMSS

year in centurary, day in year (julian date), hour 0-24, minute, second.  This also has the happy side effect of ordering the reports in the file Smiley Wink


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 6
(2,596 Views)

I have no problem using Mod arithmetic in this scenario, but if I knew for example that there would be less than 702 duplicates of any given file then I would probably do something like this:

 

LetterSuffix.png

 

You could easily add a third letter to the lookup table without too much of a memory hit.

0 Kudos
Message 3 of 6
(2,583 Views)

I started out with Array Index, but did have a few instances where I had to go to three or maybe four characters, so I wanted something that wasn't limited.

 

I was kinda hoping there was a fancy way of using regex or format into string or something that uses the logic of ordered characters, rather than the brute force of counting.

 

Oh well.

0 Kudos
Message 4 of 6
(2,580 Views)

Just for fun here is another way to do it.

 

IntegerToAlphabet.png

 

Since recursion does not work in snippets I have attached it as well.

 

For some numerology I was testing its speed on the classic text speak LMAO (219740), I was a bit surprised at what happens when you decrement the first digit (subtract 100000).

0 Kudos
Message 5 of 6
(2,563 Views)

241310672!

Message 6 of 6
(2,558 Views)