1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

How can find a string in NSString?

Discussion in 'Mac Programming' started by newformac, Jun 9, 2011.

  1. macrumors regular

    #1
    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.
     
  2. macrumors 65816

    jiminaus

    #2
    OMG, are you serious !!!???? WTF. Look in the NSString class reference. Particularly look under Finding Characters and Substrings.
     
  3. macrumors regular

    #3
    this is correct way

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

    lee1210

    #4
    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
     
  5. macrumors 6502a

    #5
    Variable Names

    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.
     
  6. macrumors regular

    #6
    thanks for the info and guidance.
     

Share This Page