Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 9, 2011, 07:45 AM   #1
newformac
Banned
 
Join Date: May 2011
How can find a string in NSString?

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.
newformac is offline   0 Reply With Quote
Old Jun 9, 2011, 07:51 AM   #2
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
OMG, are you serious !!!???? WTF. Look in the NSString class reference. Particularly look under Finding Characters and Substrings.
jiminaus is offline   0 Reply With Quote
Old Jun 9, 2011, 07:57 AM   #3
newformac
Thread Starter
Banned
 
Join Date: May 2011
this is correct way

Code:
BOOL match = ([main_str rangeOfString:find_str options:NSCaseInsensitiveSearch].location != NSNotFound);
newformac is offline   0 Reply With Quote
Old Jun 9, 2011, 07:58 AM   #4
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
As jiminaus said... the documentation is your friend:
http://developer.apple.com/library/m.../NSString.html

The appropriate method is rangeOfStringptions: 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/m...uid/TP30001163

http://developer.apple.com/library/m...uid/TP40002974

-Lee
lee1210 is online now   0 Reply With Quote
Old Jun 9, 2011, 05:02 PM   #5
PatrickCocoa
macrumors 6502a
 
Join Date: Dec 2008
Variable Names

Quote:
Originally Posted by Learner View Post
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.
__________________
iMac 21.5", 3.06GHz, 4 GB, 2 TB HD.
iPod Touch 3G.
PatrickCocoa is offline   0 Reply With Quote
Old Jun 9, 2011, 11:40 PM   #6
newformac
Thread Starter
Banned
 
Join Date: May 2011
thanks for the info and guidance.
newformac is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Searching an NSMutableArray of Objects to find a string IDMah iPhone/iPad Programming 10 Oct 14, 2011 10:47 AM
How can find guest user account in pc? newformac Mac Programming 2 Jul 1, 2011 05:19 AM
How to find live music in my area? thecritix Music Discussion 0 Jul 21, 2008 05:28 AM
How to find hidden files in 10.3.9 ezsobre OS X 1 Dec 18, 2007 08:18 PM
how to find video podcasts in itunes? andiwm2003 Mac Applications and Mac App Store 0 Oct 19, 2005 10:02 PM


All times are GMT -5. The time now is 11:23 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC