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 offline   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

Similar Threads
thread Thread Starter Forum Replies Last Post
Format string is not a string literal. larswik Mac Programming 5 Jan 17, 2014 10:45 PM
Search a string for a String of a specific format. ncaissie iPhone/iPad Programming 19 Nov 15, 2013 10:42 AM
NSString to NSSize larswik Mac Programming 1 May 28, 2013 06:54 PM
Find multiple characters in a NSString fstigre iPhone/iPad Programming 5 Jan 6, 2013 06:59 AM
(NSString*) ?? thedon1 iPhone/iPad Programming 6 Jul 2, 2012 07:52 PM

Forum Jump

All times are GMT -5. The time now is 05:06 PM.

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

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