void setup() {
Serial.begin(9600);
// 1. setCharAt(index, c)
String str1 = "Hello";
str1.setCharAt(1, 'a');
Serial.print("setCharAt: ");
Serial.println(str1);
// 2. startsWith(S2)
String str2 = "Hello";
if (str2.startsWith("He")) {
Serial.println("startsWith: Starts with He");
}
// 3. substring(index):
String str3 = "Hello";
String substr1 = str3.substring(2);
Serial.print("substring(index): ");
Serial.println(substr1);
// 4. substring(index, to):
String substr2 = str3.substring(1, 4);
Serial.print("substring(index, to): ");
Serial.println(substr2);
// 5. toCharArray(buffer, len):
char buf[6];
str3.toCharArray(buf, 6);
Serial.print("toCharArray: ");
Serial.println(buf);
// 6. toFloat():
String str4 = "123.45";
float num1 = str4.toFloat();
Serial.print("toFloat: ");
Serial.println(num1);
// 7. toInt():
String str5 = "123";
int num2 = str5.toInt();
Serial.print("toInt: ");
Serial.println(num2);
// 8. toLowerCase():
String str6 = "Hello";
str6.toLowerCase();
Serial.print("toLowerCase: ");
Serial.println(str6);
// 9. toUpperCase():
String str7 = "Hello";
str7.toUpperCase();
Serial.print("toUpperCase: ");
Serial.println(str7);
// 10. trim():
String str8 = " Hello ";
str8.trim();
Serial.print("trim: ");
Serial.println(str8);
// 11. charAt(n):
String str9 = "Hello";
char ch = str9.charAt(1);
Serial.print("charAt: ");
Serial.println(ch);
// 12. compareTo(S2):
String str10 = "Hello";
String str11 = "World";
int result = str10.compareTo(str11);
Serial.print("compareTo: ");
Serial.println(result);
// 13. concat(S2):
String str12 = "Hello ";
String str13 = "World";
str12.concat(str13);
Serial.print("concat: ");
Serial.println(str12);
// 14. endsWith(S2):.
String str14 = "Hello";
if (str14.endsWith("lo")) {
Serial.println("endsWith: Ends with lo");
}
// 15. equals(S2):
String str15 = "Hello";
String str16 = "Hello";
if (str15.equals(str16)) {
Serial.println("equals: Strings are equal");
}
// 16. equalsIgnoreCase(S2):
String str17 = "Hello";
String str18 = "hello";
if (str17.equalsIgnoreCase(str18)) {
Serial.println("equalsIgnoreCase: Strings are equal ignoring case");
}
// 17. getBytes(buffer, len):
byte buf2[6];
str17.getBytes(buf2, 6);
Serial.print("getBytes: ");
Serial.write(buf2, 5);
Serial.println();
// 18. indexOf(S):
int index1 = str17.indexOf('e');
Serial.print("indexOf: ");
Serial.println(index1);
// 19. lastIndexOf(S):
int index2 = str17.lastIndexOf('l');
Serial.print("lastIndexOf: ");
Serial.println(index2);
// 20. length():
int len = str17.length();
Serial.print("length: ");
Serial.println(len);
// 21. remove(index):.
String str19 = "Hello";
str19.remove(1);
Serial.print("remove(index): ");
Serial.println(str19);
// 22. remove(index, count):
String str20 = "Hello";
str20.remove(1, 2);
Serial.print("remove(index, count): ");
Serial.println(str20);
// 23. replace(A, B):
String str21 = "Hello";
str21.replace('l', 'x');
Serial.print("replace: ");
Serial.println(str21);
// 24. reserve(count):
String str22;
str22.reserve(10);
str22 = "Hello";
Serial.print("reserve: ");
Serial.println(str22);
}
void loop() {
// put your main code here, to run repeatedly:
}