How to compare Strings sent to Processing by Arduino board

I'm using arduino with processing. I'm sending a 10 character string from arduino to processing, using Serial.prinln(); I receive the same string in processing without any problem. But when I compare the same string inside the Serial Event function in processing, it doesn't match. I don't understand the reason. I tried different reading methods. nothing work. Then i read the serial port using a byte character array and converted it to string and then compared it. doesn't work. I need to used these serial read strings to load a picture to the window and display. Please help.

Tagged:

Answers

  • This question been asked and answered many times, it is also in both the wiki and the reference:

    http://wiki.processing.org/w/Strings_and_Equality

    http://processing.org/reference/String_equals_.html

    Next time please:

    1. Search first.
    2. Post the relevant code with specific questions like these.
  • edited August 2014

    In Java, when the equality operator == is used to compare objects, that is,
    anything which isn't any of the 8 primitive types, what is actually compared is their memory addresses!

    A String is an object, hence it resides in a contiguous block of memory from some unique memory address.
    That's why the equals() method exists, in order to compare the object contents rather their references!

    Generally, other programming languages can be less rigid.
    And their == operator work as we think they should! ;)

Sign In or Register to comment.