Page 1 of 1

Converting Numbers to Alphabates

Posted: Thu Sep 15, 2005 9:45 am
by bapajju
Hello,

I have an input string that can have length of 2 or 4 or 6. The values for this stri will look like:

01
1201
120616

we need to convert these values to corresponding Alphabates. So the above string needs to get converted to:
A
LA
LFP

Could anyone please help me in this. How can we achieve this.

Thanks in advance

Posted: Thu Sep 15, 2005 9:54 am
by I_Server_Whale
Hi bapajju,

You can use 'If then Elseif then Else' block. Use it in the derivation of the ouput field you are mapping to.

For example;

Code: Select all


If DSLink.String = '01' Then 'A' Else If DSLink.String = '1201' Then 'LA' Else If DSLink.String = '120616'  Then 'LFP' Else DSLink.String
Naveen.

Posted: Thu Sep 15, 2005 11:34 am
by bapajju
Thanks Naveen. Appreciate your suggestion. This is not just limited to these numbers. We need to conver 01 to 26 to all corresponding Alphabates. But trick is the field length can be 2 or 4 or 6.

Thanks
naveendronavalli wrote:Hi bapajju,

You can use 'If then Elseif then Else' block. Use it in the derivation of the ouput field you are mapping to.

For example;

Code: Select all


If DSLink.String = '01' Then 'A' Else If DSLink.String = '1201' Then 'LA' Else If DSLink.String = '120616'  Then 'LFP' Else DSLink.String
Naveen.

Posted: Thu Sep 15, 2005 12:29 pm
by ArndW
bapaju,

if you always have 2 digit codes and the numbers you have represent the position in the alphabet then you can use the CHAR(64+{number}) to get the appropriate letter. Since you said your string could be 2, 4 or 6 then the one-line derivation could be:

Code: Select all

IF LEN(In.String=2) THEN CHAR(64+In.String[1,2]) ELSE IF LEN(In.String=4) THEN CHAR(64+In.String[1,2]):CHAR(64+In.String[3,2]) ELSE IF LEN(In.String=6) THEN CHAR(64+In.String[1,2]):CHAR(64+In.String[3,2]):CHAR(64+In.String[5,2]) ELSE 'ERROR'
It would be prettier in a subroutine than in a one-liner.








:IF LEN(In.String)>2 THEN

Posted: Thu Sep 15, 2005 12:33 pm
by chulett
Write a custom routine. Build a alphabet string with all letters from A to Z. Loop through the input argument two bytes at a time and build an output string, concatenating on the results of pulling AlphaString[number,1] each time.

Or build an array to pluck letters from and take AlphaArray<number>.

Or there is Arnd's way. :wink:

Posted: Thu Sep 15, 2005 4:31 pm
by ray.wurlod
Dynamic array manipulation?

Code: Select all

Convert(@FM,"",Chars(Adds(Fold(TheString,2),REUSE(64)))

Posted: Thu Sep 15, 2005 6:40 pm
by bapajju
Thanks Arnd:). It was great. Itried it and it worked perfect. Thanks again
ArndW wrote:bapaju,

if you always have 2 digit codes and the numbers you have represent the position in the alphabet then you can use the CHAR(64+{number}) to get the appropriate letter. Since you said your string could be 2, 4 or 6 then the one-line derivation could be:

Code: Select all

IF LEN(In.String=2) THEN CHAR(64+In.String[1,2]) ELSE IF LEN(In.String=4) THEN CHAR(64+In.String[1,2]):CHAR(64+In.String[3,2]) ELSE IF LEN(In.String=6) THEN CHAR(64+In.String[1,2]):CHAR(64+In.String[3,2]):CHAR(64+In.String[5,2]) ELSE 'ERROR'
It would be prettier in a subroutine than in a one-liner.








:IF LEN(In.String)>2 THEN