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

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -