如何检查字符串是否包含URL

Aja*_*mar 0 iphone nsstring

我有短信,我想检查它是否包含文本"http"或URL存在.

我该如何检查?

Cyp*_*ian 6

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)