Skip to content

Commit 0778f8a

Browse files
committed
Added remove methods to WString
1 parent 22320db commit 0778f8a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

hardware/arduino/cores/arduino/WString.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,22 @@ void String::replace(const String& find, const String& replace)
604604
}
605605
}
606606

607+
void String::remove(unsigned int index){
608+
if (index >= len) { return; }
609+
int count = len - index;
610+
remove(index, count);
611+
}
612+
613+
void String::remove(unsigned int index, unsigned int count){
614+
if (index >= len) { return; }
615+
if (count <= 0) { return; }
616+
if (index + count > len) { count = len - index; }
617+
char *writeTo = buffer + index;
618+
len = len - count;
619+
strncpy(writeTo, buffer + index + count,len - index);
620+
buffer[len] = 0;
621+
}
622+
607623
void String::toLowerCase(void)
608624
{
609625
if (!buffer) return;

hardware/arduino/cores/arduino/WString.h

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ class String
164164
// modification
165165
void replace(char find, char replace);
166166
void replace(const String& find, const String& replace);
167+
void remove(unsigned int index);
168+
void remove(unsigned int index, unsigned int count);
167169
void toLowerCase(void);
168170
void toUpperCase(void);
169171
void trim(void);

0 commit comments

Comments
 (0)