From 15f51fc1f804a86928448f5a54a2850a291cfc73 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Mon, 29 Nov 2010 11:31:00 -0500 Subject: added toInt() function to WString --- 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