Relay shield example help


I’m new to particle and trying to figure out some of the code. In the relay shield example:

there is a line of code:
int relayNumber = command.charAt(1) - ‘0’;

I understand everything except why
is at the end of the line.
Can anyone shed light on this?


command.charAt(1) returns a character, which will be 1, 2, 3, etc. as an ASCII character code, which has a numerical value of 49, 50 and 51, respectively. What’s that’s doing is subtracting the value of the ASCII character code for zero (a numerical value of 48), to get a numerical value of 1, 2, 3, etc. corresponding to a relay number.