void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println(remove_repeated("Vodacom VodaCom Tanzania"));
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
String remove_repeated(String mm) {
const char delimiter_here = ' ';
if ( ! hasChar(mm, delimiter_here) ) {
return mm;
}
String aa[10];
splitting(mm, aa, delimiter_here);
String vv = "";
for ( byte x = 0; x < 8; x++ ) {
String jj = aa[x];
String nn = jj;
jj.toLowerCase();
if ( jj.length() < 2 ) {
continue;
}
if ( vv.indexOf(jj) >= 0 ) {
continue;
}
vv += jj + delimiter_here;
}
vv.trim();
if ( vv.length() < 2 ) {
vv = mm;
}
return vv;
}
void splitting(String splitMsg, String bb[], char delimiter) {
int counter = 0 ;
for ( int i = 0 ; i < splitMsg.length() ; i ++ ) {
if ( splitMsg.charAt(i) == delimiter ) {
counter++;
}
else {
bb[counter] += splitMsg.charAt(i) ;
}
}
}
bool hasChar(String mm, const char tt) {
int dd = mm.length();
if ( dd < 2 ) {
return false;
}
for ( int x = 0; x < dd; x++ ) {
char cc = mm.charAt(x);
if ( cc == tt ) {
return true;
}
} // end for loop
return false;
}