-3

I am trying to convert every letter in the alphabet to an integer like this

A = 1;
B = 2;
...
Z = 26;

I went through some forum questions but none of them worked well. Is there a way of doing this without Arrays?

Mike Mertsock
  • 11,825
  • 7
  • 42
  • 75

1 Answers1

0

for lowercase letters you need to subtract 96 from its value. Like this:

int a = 'a' - 96; // 1

for uppercase ones subtract 64. Like this:

int A = 'A' - 64;// 1

This will work for any letter of English alphabet

Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161