diff options
Diffstat (limited to 'cores/arduino/WString.cpp')
-rw-r--r-- | cores/arduino/WString.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index 2718956..b13123b 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -434,3 +434,19 @@ void String::toCharArray(char *buf, unsigned int bufsize) strncpy(buf, _buffer, len); buf[len] = 0; } + + +long String::toInt() { + String temp = _buffer; + long value = 0; + + for (unsigned int charPos = 0; charPos < _length; charPos++) { + int thisChar = temp[charPos]; + if (isdigit(thisChar)) { + value *= 10; + value += (thisChar - '0'); + } + } + + return value; +} |