diff options
Diffstat (limited to 'cores')
-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); |