Determines whether a string is equal isequaltostring:

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.