Can someone tell me why the line
s[i]=s[i]-'a'+'A';
does the job of converting lower case to upper case? More specifically, I do not understand
why 'a'
and 'A'
get substituted by the corresponding characters from string s
.
string s="Print My Name";
for (int i=0; i<s.length(); i++)
{
if (s[i]>='a' && s[i]<='z')
{
s[i]=s[i]-'a'+'A';
}
}