If you insist on using String:
Much better would be to use a string (null terminated char array) and atoi or strtol: