diff options
author | Ryan Esteves <snargledorf@gmail.com> | 2013-06-05 14:08:59 -0400 |
---|---|---|
committer | Ryan Esteves <snargledorf@gmail.com> | 2013-06-05 14:08:59 -0400 |
commit | 6bef2ada0627be776e463661ccbcdeba5a373f3a (patch) | |
tree | ef29cd25e4e7b742345c5ecbf57a4150ef5158de /cores/arduino | |
parent | ef4e8c65373f531ce6d37ff226a21fc9b358ff29 (diff) |
Added remove methods to WString
Diffstat (limited to 'cores/arduino')
-rw-r--r-- | cores/arduino/WString.cpp | 16 | ||||
-rw-r--r-- | cores/arduino/WString.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index c6839fc..aab2a54 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -604,6 +604,22 @@ void String::replace(const String& find, const String& replace) } } +void String::remove(unsigned int index){ + if (index >= len) { return; } + int count = len - index; + remove(index, count); +} + +void String::remove(unsigned int index, unsigned int count){ + if (index >= len) { return; } + if (count <= 0) { return; } + if (index + count > len) { count = len - index; } + char *writeTo = buffer + index; + len = len - count; + strncpy(writeTo, buffer + index + count,len - index); + buffer[len] = 0; +} + void String::toLowerCase(void) { if (!buffer) return; diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h index 642b016..b587a3d 100644 --- a/cores/arduino/WString.h +++ b/cores/arduino/WString.h @@ -164,6 +164,8 @@ public: // modification void replace(char find, char replace); void replace(const String& find, const String& replace); + void remove(unsigned int index); + void remove(unsigned int index, unsigned int count); void toLowerCase(void); void toUpperCase(void); void trim(void); |