iPhone Objective-C Compare String values

November 10, 2009 § 1 Comment

isEqualToString: method should be used to compare values of the string objects.

if([myString isEqualToString:@”1″] || [myString isEqualToString:@”2″] || [myString isEqualToString:@”3″])
action = @”showDifferences”;

If you use the == operator on strings, you are comparing the strings’ addresses (allocated memory) rather than the values of the string objects.

if(myString==@”1″ || myString ==@”2″ || myString ==@”3″)
action = @”showDifferences”;

Advertisements

§ One Response to iPhone Objective-C Compare String values

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading iPhone Objective-C Compare String values at Web Builders.

meta

%d bloggers like this: