StringComparisonOperators

StringComparisonOperators - /* Comparing Strings Examples...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Comparing Strings Examples of how to compare strings using the comparison operators created 27 July 2010 modified 4 Sep 2010 by Tom Igoe http://arduino.cc/en/Tutorial/StringComparisonOperators This example code is in the public domain. */ String stringOne, stringTwo; S void setup() { Serial.begin(9600); stringOne = String("this"); stringTwo = String("that"); Serial.println("\n\nComparing Strings:"); } void loop() { // two strings equal: if (stringOne == "this") { Serial.println("StringOne == \"this\""); } // two strings not equal: if (stringOne != stringTwo) { Serial.println(stringOne + " =! " + stringTwo); } // two strings not equal (case sensitivity matters): stringOne = "This"; stringTwo = "this"; if (stringOne != stringTwo) { Serial.println(stringOne + " =! " + stringTwo); } // you can also use equals() to see if two strings are the same: if (stringOne.equals(stringTwo)) { Serial.println(stringOne + " equals " + stringTwo); } else { Serial.println(stringOne + " does not equal " + stringTwo);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

StringComparisonOperators - /* Comparing Strings Examples...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online