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

    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


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

    this is correct way

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


    As jiminaus said... the documentation is your friend:

    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:


  5. macrumors 6502a

    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

    thanks for the info and guidance.

Share This Page