~ubuntu-branches/debian/experimental/arduino/experimental

« back to all changes in this revision

Viewing changes to build/shared/examples/8.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.pde

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2012-03-11 18:19:42 UTC
  • mfrom: (1.1.5) (5.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120311181942-be2clnbz1gcehixb
Tags: 1:1.0.1~rc1+dfsg-1
New upstream release, experimental.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  String startWith() and endsWith()
3
 
 
4
 
 Examples of how to use startsWith() and endsWith() in a String
5
 
 
6
 
 created 27 July 2010
7
 
 modified 4 Sep 2010
8
 
 by Tom Igoe
9
 
 
10
 
 http://arduino.cc/en/Tutorial/StringStartsWithEndsWith
11
 
 
12
 
 This example code is in the public domain.
13
 
 */
14
 
 
15
 
void setup() {
16
 
  Serial.begin(9600);
17
 
  Serial.println("\n\nString startsWith() and endsWith():");
18
 
 
19
 
}
20
 
 
21
 
void loop() {
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"); 
27
 
  } 
28
 
  
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"); 
33
 
  } 
34
 
  
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"); 
41
 
  } 
42
 
  else {
43
 
    Serial.println(". This reading is not divisible by ten"); 
44
 
 
45
 
  }
46
 
 
47
 
// do nothing while true:
48
 
 while(true);
49
 
}
 
 
b'\\ No newline at end of file'