diff options
author | Tom Igoe <tom.igoe@gmail.com> | 2010-11-29 11:31:00 -0500 |
---|---|---|
committer | Tom Igoe <tom.igoe@gmail.com> | 2010-11-29 11:31:00 -0500 |
commit | 15f51fc1f804a86928448f5a54a2850a291cfc73 (patch) | |
tree | 33beb77b848f7294592eb01af70651cf617772fb /cores/arduino/WString.cpp | |
parent | eb9c51d43c451b3e48725d04af519d8a6c36107b (diff) |
added toInt() function to WString
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; +} |