Detecting if an NSString contains…?

后端 未结 7 2084
长情又很酷
长情又很酷 2021-01-30 03:37

How can I detect if a string contains a certain word? For example, I have a string below which reads:

@\"Here is my string.\"

I\'d like to know

7条回答
  •  不思量自难忘°
    2021-01-30 04:03

    I hope this helps you,.. add this line at .m file or create a separate class and integrate this code.

    @implementation NSString (Contains)
    
    - (BOOL) containsString: (NSString*) substring
    {
    NSRange range = [self rangeOfString : substring];
    BOOL found = ( range.location != NSNotFound );
    return found;
    }    
    @end
    

提交回复
热议问题