java - Why subtract 'a' -


can explain line of code ?

for(k=0; k < limit; k++) {     int index = s.charat(k) - 'a';     <---> line } t.myisword = true; 

why is - 'a' ? don't understand

int index = s.charat(k) - 'a'; 

in java char can casted int. each character has int value, it's not true 'a' 0 , 'b' 1. values different (based on position in ascii table).

to 'a' 0, 'b' 1, etc. need subtract 'a' given character.

this line does.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

monitor web browser programmatically in Android? -

c# - Using multiple datasets in RDLC -