Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newformac

macrumors regular
Original poster
May 24, 2011
107
0
Hi all,

please tell me how can i find the NSString variable contains given string or not?

and it should not be case sensitive.

like "Ani" find in ani, ANI, Ani, aNi , anicol ,ANIMAL etc.

please help me for this thanks in advance.
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
OMG, are you serious !!!???? WTF. Look in the NSString class reference. Particularly look under Finding Characters and Substrings.
 

newformac

macrumors regular
Original poster
May 24, 2011
107
0
this is correct way

Code:
BOOL match = ([main_str rangeOfString:find_str options:NSCaseInsensitiveSearch].location != NSNotFound);
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
As jiminaus said... the documentation is your friend:
http://developer.apple.com/library/...lasses/NSString_Class/Reference/NSString.html

The appropriate method is rangeOfString:eek:ptions: with NSCaseInsensitiveSearch as your option mask.

It sounds like, based on your posts, that you are trying to write a program without having learned the language/frameworks. You might want to start here:
http://developer.apple.com/library/...bjectiveC.html#//apple_ref/doc/uid/TP30001163

http://developer.apple.com/library/...roduction.html#//apple_ref/doc/uid/TP40002974

-Lee
 

PatrickCocoa

macrumors 6502a
Dec 2, 2008
751
149
Variable Names

this is correct way

Code:
BOOL match = ([main_str rangeOfString:find_str options:NSCaseInsensitiveSearch].location != NSNotFound);

I'm assuming "main_str" is an NSString you've created somewhere else. In which case you should make your variable names more useful (and match the Cocoa development guidelines). Something like "nameOfBaby" or "typeOfBuilding".

Also "match" should be "nicknameFoundInNameOfBaby" or "subtypeFoundInTypeOfBuilding" or something like that.

LearnerSixMonthsFromNow will thank Learner.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.