4

There is String.toInt(), but no String.toLong() or the many other variations. Do I have to resort to atol(String.c_str()) or is there a better way to convert a String to a long?

5

Using atol(String.c_str()) looks OK to me. If there was a String.toLong() it would be written that way anyway.

In fact, looking at the code for String.toInt() that's exactly what it does:

long String::toInt(void) const
{
    if (buffer) return atol(buffer);
    return 0;
}

So the answer is: use String.toInt().

  • 1
    Interesting. I wonder why they didn't just call it toLong()?? – Sound Conception Aug 24 '17 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.