Return the length of a String with .length in Arduino

Description: The length of a String can be found with .remove and displayed on the Serial Monitor.

Return the length of a String in Arduino

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

Serial Monitor Return the length of a String

Supplies:

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

Arduino Code:

void setup() {
  
   Serial.begin(9600);
    
   Serial.println();
   String s1 = "nano_3t1h6dyn48tm9kidssuqcmz3tyc5fowcoy9byp8hmcffb56165c69may459d";
   Serial.println(s1);
   Serial.println();

   int length = s1.length();
   Serial.println(length);
  
}

void loop() {

}

Leave a Comment

− 3 = 4