From 4a90c4bd405acc874239d82511a35c377b494dff Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 29 Nov 2010 15:20:30 -0500 Subject: Redoing 448222e4b65e0cf44dfc0c494f7f76901f1fabea without all the extra files. Adds toInt() to String, WCharacter.h (from Wiring), and an SD Datalogger example. --- cores/arduino/WString.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cores/arduino/WString.cpp') 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; +} -- cgit v1.2.3-18-g5258