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
Converting Numbers to Alphabates
Moderators: chulett, rschirm, roy
-
- Premium Member
- Posts: 1255
- Joined: Wed Feb 02, 2005 11:54 am
- Location: United States of America
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;
Naveen.
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
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
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;
Naveen.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
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:
It would be prettier in a subroutine than in a one-liner.
:IF LEN(In.String)>2 THEN
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'
:IF LEN(In.String)>2 THEN
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 :wink:](./images/smilies/icon_wink.gif)
Or build an array to pluck letters from and take AlphaArray<number>.
Or there is Arnd's way.
![Wink :wink:](./images/smilies/icon_wink.gif)
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Dynamic array manipulation?
Code: Select all
Convert(@FM,"",Chars(Adds(Fold(TheString,2),REUSE(64)))
Last edited by ray.wurlod on Thu Sep 15, 2005 8:18 pm, edited 2 times in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
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:
It would be prettier in a subroutine than in a one-liner.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'
:IF LEN(In.String)>2 THEN