# integer to character string

This topic is 7475 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

3->C

28 -> AB

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

##### 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.

##### Share on other sites

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).

(* any suggestions are still welcome *)

Jitse

##### 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. If not, I'll keep trying tomorrow when I have some extra time. This one is really a brain-killer!

Cheers!

##### Share on other sites

collegea and I have been dicussing this problem again the whole morning.

So it better be a complex problem otherwise we will have an image problem to work on also

Have a good night sleep

Jitse schaafsma

##### Share on other sites

Thanks, I slept for 3 hours, but I still feel somewhat intelligent.

Could I ask what exactly this process is for?

##### 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)

Thanks

Jitse

##### Share on other sites

Hey,

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.

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

##### Share on other sites

Actually, Ugo, the hard-coded one took about 20 minutes. It's the calcs I'm not showing anyone yet that took all night.

##### Share on other sites

Hi,

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

Thanks

jitse

##### Share on other sites

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

## Create an account

Register a new account