arduino-string

Migrate from https://cmakerhk.wordpress.com/2018/10/22/string-on-arduino/


Ref: https://www.arduino.cc/en/Tutorial/StringComparisonOperators

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Test of String");

  Serial.print("\"Hello\" == \"Hello\" : ");
  Serial.println("Hello" == "Hello");     //return 1: true

  Serial.print("\"Hello\" > \"Hell\" : ");
  Serial.println("Hello" > "Hell");     //return 0: false

  Serial.print("\"Hello\" < \"Hell\" : ");
  Serial.println("Hello" < "Hell");     //return 1: true

  Serial.print("\"AB\" < \"CD\" : ");
  Serial.println("AB" < "CD");     //return 1: true

  Serial.print("\"AB\" < \"ABCD\" : ");
  Serial.println("AB" < "ABCD");     //return 1: true

  Serial.print("\"99\" < \"100\" : ");
  Serial.println("999" < "1000");     //return 1: true

  Serial.print("99 < \"100\" : ");
  Serial.println(99 < "100");     //return 1: true
}

It doesn’t match what the website said. Conclusion: except for two identical string. Don’t use compare in String.