if ((Btn.currenttitle = = answerbtn.currenttitle) && Btn.hidden = = YES)
String equality comparison is not directly compared to the pointer, not the data pointed to by the pointer
if ([Btn.currenttitle isEqualToString:answerBtn.currentTitle] && Btn.hidden = = YES)
NSString *stra = [NSString stringWithFormat:@ "a"*strb = [NSString stringWithFormat:@ "b"]; if (Stra = = StrB) NSLog (@ "A is equal to B"); Else NSLog (@ "A is not equal to B");
To run this code, the output on the console is: A was not equal to B
The code makes some changes to set the stra to be equal to STRB.
NSString *stra = [NSString stringWithFormat:@ "a"*strb = [NSString stringWithFormat:@ "a"]; if (Stra = = StrB) NSLog (@ "A is equal to B"); Else NSLog (@ "A is not equal to B");
Running this code, the output on the console is still a is not equal to B.
What is this for? The problem is on the statement of the string comparison.
if (stra = = StrB)//This stra, StrB is a pointer, although the contents of the string is the same, but the pointer to the string is certainly different, it cannot be the same AH. (To better understand the string, you need to figure out the concept of pointers.) Allocation of memory. )
Error: if (stra = = StrB)
Correct: if ([Stra isequaltostring: StrB])
The IOS SDK itself also provides a way to compare strings: isequaltostring:
Determines whether a string is equal isequaltostring: