Convert integer into its character equivalent, where 0 => a, 1 => b, etc

前端 未结 12 792
无人共我
无人共我 2020-11-28 02:52

I want to convert an integer into its character equivalent based on the alphabet. For example:

0 => a
1 => b
2 => c
3 => d

etc.

12条回答
  •  离开以前
    2020-11-28 03:27

    If you are looking for TypeScript working functions then follow

    public numericValue = (alphaChar: any) => alphaChar.toUpperCase().charCodeAt(0) - 64;
    
    public alphaValue = (numericDigit: any) => 
       String.fromCharCode(64 + numericDigit) : '';
    

    You can make several checks like (numericDigit >= 1 && numericDigit <= 26) ? inside function body as per the requirements.

提交回复
热议问题