How to Remove Characters from a String in Arduino with .remove

Description: Characters from a String are removed with .remove and displayed on the Serial Monitor.

Remove Characters from a String in Arduino

Notes: Make sure the baud rate is set to 9600 in the Serial Monitor as shown below.

Serial Monitor Remove Characters from a String with Arduino

Supplies:

1 – Breadboard 400 Points
1 – Wemos Lolin D1 Mini Pro V2

Arduino Code:

void setup() {
  
   Serial.begin(9600);
    
   Serial.println();
   String s1 = "Rio de Janeiro";
   String s2 = "Vitoria.com";
   String s3 = "Sal87vador";

   Serial.println(s1);
   Serial.println(s2);
   Serial.println(s3);
   Serial.println();

   s1.remove(3,11); //Remove 11 characters starting from position 3
   s2.remove(7); //Remove all characters starting from position 7
   s3.remove(3,2); //Remove 2 characters starting from position 3

   Serial.println(s1);
   Serial.println(s2);
   Serial.println(s3); 
  
}

void loop() {

}

Leave a Comment

53 + = 59