2
String startWith() and endsWith()
4
Examples of how to use startsWith() and endsWith() in a String
10
http://arduino.cc/en/Tutorial/StringStartsWithEndsWith
12
This example code is in the public domain.
17
Serial.println("\n\nString startsWith() and endsWith():");
22
// startsWith() checks to see if a String starts with a particular substring:
23
String stringOne = "HTTP/1.1 200 OK";
24
Serial.println(stringOne);
25
if (stringOne.startsWith("HTTP/1.1")) {
26
Serial.println("Server's using http version 1.1");
29
// you can also look for startsWith() at an offset position in the string:
30
stringOne = "HTTP/1.1 200 OK";
31
if (stringOne.startsWith("200 OK", 9)) {
32
Serial.println("Got an OK from the server");
35
// endsWith() checks to see if a String ends with a particular character:
36
String sensorReading = "sensor = ";
37
sensorReading += analogRead(A0);
38
Serial.print (sensorReading);
39
if (sensorReading.endsWith(0)) {
40
Serial.println(". This reading is divisible by ten");
43
Serial.println(". This reading is not divisible by ten");
47
// do nothing while true:
b'\\ No newline at end of file'