17
Views
7
###### Numertic to Alphabet
Question

Hey there,

I need to convert numeric input into the alphabet.

for eg,

I get input as 1 and I need to send the output as A

likewise 2 as B,

3 as C, etc...

Is there any Built-in function to attain this scenario?

As of now, I'm using a switch to convert for 26 numbers, but if it goes more than that I have no idea how to do it.

Hi Manoj,

there isn't any function for that but you can make it easily by creating a Static Entity mapping the number to the alphabet char.

If you need more clarification, let me know.

Hi Jose,

I need to do this without a database creation. Is there any other way to do this?

You can create in the Preparation of your screen. Create a list with a structure of number and char and map it.

If you need it in several screens, use a Session variable to store although is not much recommended due to possible performance issues.

Champion

Hi Manoj,

You can use the Built-In Chr() function for this. This function gets the ASCII code of a character and outputs the alphabetic character. For example, Char(65) outputs A.

So, in your case, you can use the numeric input, e.g. input = 1, to output 'A' using Chr(64 + input).

Regards,
Lennart

Hi Lennart,

Thanks for your response, your idea partially worked for me, It reduced my current code. Instead of using the switch, I used this "Chr(64 + input)"  but if my input  > 27 means it gives output in a special character.

Champion

Hi Manoj,

I read a little too fast, that's why I missed the real problem here.

I don't know your exact use case, but you can check if the input is <= 26. In that case use the 64+ input. If the input is > 26, then you can use 101 + input to start from 128 (Ç). But it feels more like a hack than a good solution to be fair.

Hi  Manoj,

You use js to achieve that or adapt for your code, check this example, it returns undefined if the number is outside of you range

Eg:.

const toAlpha = (num) => {

if(num < 1 || num > 26 || typeof num !== 'number'){

return;

}

const leveller = 64;

//since actually A is represented by 65 and we want to represent it

return String.fromCharCode(num + leveller);

};

console.log(toAlpha(1));

console.log(toAlpha(2));

console.log(toAlpha(26));

console.log(toAlpha(27));