Jump to content

integer to character string

This topic is 6565 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Let me explain what i want to do:

convert a integer to a string

1 -> A


28 -> AB

60 > AD

360 -> MV

This is easy : dived the integer by 26: this is X and the remainder of (integer-X * 26) is Y.

As long as X and Y are less then 27 i can translate both to a character between A and Z.

The problem starts with integers larger then 26 * 26 = 676.

I have the feeling that a need some kind of recursive procedure.

I do not want to create a script because i need this calculation in a Web bsed environment.

Could someone suggest a solution to translate integers to sequences of characters.

Many thanks

Jitse Schaafsma

Link to comment
Share on other sites

I'm assuming you only want to go to 702, i.e. all one- or two-character alphabet strings. If this is the case, then

Right( Middle( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Int( Integer / 26 ) - ( not Mod( Integer, 26 ) ), 1 ), Integer > 26 ) &

Right( Middle( "ZABCDEFGHIJKLMNOPQRSTUVWXYZ", Mod( Integer, 26 ) + 1, 1 ), Length( Integer ) > 1 or Integer < 27 )

will do the job.

If you require it to extend greater than 2 characters, let me know.

Oh, and by the way, I assumed you made a typo and that 60 -> BD and not AD. wink.gif

Link to comment
Share on other sites

Thanks for your respond

and yes i made a typo (even at junior school i had trouble with the alfabet).

and yes your solution is partly what i wanted, however i do not want to restrict myself to a preknown maximum of the integer. (if the maximum is known then i would have to use your code and extend it to any number of characters i need (based on the known maximum of the integer).

So i hope that i can build a kind of recursive mechanisme within a calculation field (not a a script beacause of the web based functionality).

Anyway, thanks for your support.

(* any suggestions are still welcome *)


Link to comment
Share on other sites

Well, I've been working on this thing for half the night and further frustrating my already tired brain. Perhaps DJ will offer some assistance. wink.gif If not, I'll keep trying tomorrow when I have some extra time. This one is really a brain-killer!

Cheers! grin.gif

Link to comment
Share on other sites

We are working on a web based application for rental of equipment. The equipement can be diveded into groeps, subgroups, subsubgroups and so on. (the administrator can decide oon the number of levels of this tree sytructure.

We want to put all this info in one database (and not in seperate related files because then when the admin wants to define a new group he has to create a new file).

So each node in the tree needs a unique id that includes the id of its parent.

a three level deep node will have an id of for example AAA#BCD#FGE.

In that way we can easily build self join relations.

Anyway the problem is in generating the node id (between the # tags) where we do not retrict ourselves to the maximum number of nodes.

I hope this info helps you to get convinced that my Q is usefull (big smile)



Link to comment
Share on other sites


I was very impressed by Queue's calculation, and I'm somewhat relief to see it took him part of the night to end up with it. smile.gif

Now, I think you'd loose the dynamics required by building a tree the way you planned.

A while back, I played with such a structure of data, expanding a tree up to 12 branchs, relying only one a recursive "scripted" structure. There were even some one to many situations in it, and the whole trick was to play on an association of the Level and the Key, which actually was a standard text sequential structure of type ID0001...

my 2 cents

Link to comment
Share on other sites


we also considered using a script, then it could easily be done (i mean the recursive part).

But the node Id is generated as a part of a web application (CDML). And then it is not a wise thing to use scripts.

Today, we took an easy solution and just limited the ID to max 4 characters (AAAA) and unlimited tree structure (every branche is divided by #) : ABVF#DGHT# etc



Link to comment
Share on other sites

This topic is 6565 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.