diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2010-11-29 15:20:30 -0500 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2010-11-29 15:20:30 -0500 |
commit | 4a90c4bd405acc874239d82511a35c377b494dff (patch) | |
tree | 33beb77b848f7294592eb01af70651cf617772fb /cores/arduino/WString.cpp | |
parent | 80c5173bfd304e91e688ade4dd650efb7d35c2ee (diff) |
Redoing 448222e4b65e0cf44dfc0c494f7f76901f1fabea without all the extra files.
Adds toInt() to String, WCharacter.h (from Wiring), and an SD Datalogger example.
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; +} |