How would I compare two strings if they are not equal?
Note: When comparing two strings in java, we should not use the == or != operators. These operators actually test references, and since multiple String objects can represent the same String, this is liable to give the wrong answer.
!= will only check value regardless of operands type. but !== is used to compare both value & type of 2 operands that are being compared to each other.
Relational Operators in C++ C++ Relational operators such as '==' and '!= ' can be useful in the comparison of string at an ease.
You should not use == (equality operator) to compare these strings because they compare the reference of the string, i.e. whether they are the same object or not. On the other hand, equals() method compares whether the value of the strings is equal, and not the object itself.
Just use isEqualToString and put an ! before the whole expression, like so:
if (![self.passwordField.text isEqualToString: self.confirmPasswordField.text])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With