NSString indexOf in Objective-C

前端 未结 4 789
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-28 11:31

Is there anything similar to an indexOf function in the NSString objects?

4条回答
  •  清歌不尽
    2020-12-28 12:11

    If you want just know when String a contains String b use my way to do this.

    #define contains(str1, str2) ([str1 rangeOfString: str2 ].location != NSNotFound)
    
    //using 
    NSString a = @"PUC MINAS - BRAZIL";
    
    NSString b = @"BRAZIL";
    
    if( contains(a,b) ){
        //TO DO HERE
    }
    

    This is less readable but improves performance

提交回复
热议问题