0

Assigning and printing the value of each character of the alphabet based on their position.

Is there any shortcut to do that like (a=1,b=2,c=3.....z=26)

20th Feb 2022, 6:52 AM
Rajnish Singh
Rajnish Singh - avatar
1 Answer
+ 3
Each character has an ASCII value. That is, every letter has a numberic value. They are consecutive in the encoding. To turn any lowercase letter into its position in the alphabet, subtract 'a': 1 + (c - 'a'), where c is the character in question. For uppercase letters similarly. If the case is irrelevant ('A' ~ 'a' ~ 1), then you can lowercase the letter first: 1 + (( c | 32) - 'a' )
20th Feb 2022, 7:53 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar