Search VG Five
History
« iGoozex 1.1.1 update on the way | Main | Go Series updates »
Wednesday
May062009

NSString - Comparing two strings in Objective-C

Comparing strings in Obj-C is not done the same way as comparing two integers, bools, or even characters. For example, the following code will fail to get the desired results:

if (someString == @"someText") { // do stuff }

This will never run, because you are comparing pointers and not the content of the two strings. Instead, use this:

if ([someString isEqualToString:@"someText"]) { // do stuff }

 

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.