NSString *string = @"xxx http://someaddress.com";
NSString *substring = @"http:";
Run Code Online (Sandbox Code Playgroud)
区分大小写示例:
NSRange textRange = [string rangeOfString:substring];
if(textRange.location != NSNotFound){
//Does contain the substring
}else{
//Does not contain the substring
}
Run Code Online (Sandbox Code Playgroud)
不区分大小写的示例:
NSRange textRange = [[string lowercaseString] rangeOfString:[substring lowercaseString]];
if(textRange.location != NSNotFound){
//Does contain the substring
}else{
//Does not contain the substring
}
Run Code Online (Sandbox Code Playgroud)