不必一个字符一个字符的匹配。
+ (void)openUrl:(NSString*)link
{
if(0 == [link length])
return;
NSRange range = [link rangeOfString:@"target=_blank"];
if(range.location != NSNotFound)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:link]];
}
}
【原文:http://www.cnblogs.com/love-lie/archive/2012/05/16/2503924.html】
=====================================================
http://blog.csdn.net/like7xiaoben/article/details/7815168
NSString *str1 = @"can you \n speak English";
NSString *str = @"\n";
//在str1这个字符串中搜索\n,判断有没有
if ([str1 rangeOfString:str].location != NSNotFound) {
NSLog(@"这个字符串中有\n");
}
//rangeOfString 前面的参数是要被搜索的字符串,后面的是要搜索的字符
//NSNotFound 表示请求操作的某个内容或者item没有发现,或者不存在
=====================================================