Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two strings if they are not equal

Tags:

objective-c

How would I compare two strings if they are not equal?

like image 471
rose Avatar asked Aug 19 '10 10:08

rose


People also ask

Can you use != With strings?

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.

What is the difference between != And !==?

!= 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.

Can you use != To compare strings in C++?

Relational Operators in C++ C++ Relational operators such as '==' and '!= ' can be useful in the comparison of string at an ease.

Can you compare strings with ==?

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.


1 Answers

Just use isEqualToString and put an ! before the whole expression, like so:

if (![self.passwordField.text isEqualToString: self.confirmPasswordField.text])
like image 95
Jonathan Chiu Avatar answered Oct 01 '22 11:10

Jonathan Chiu