2011-04-06 116 views

回答

16

你可以試試這個:

NSString *originalString; 
NSString *compareString; 

讓你string存儲在originalString和要比較substring存儲在compareString

if ([originalString rangeOfString:compareString].location==NSNotFound) 
{  
    NSLog(@"Substring Not Found"); 
} 
else 
{ 
    NSLog(@"Substring Found Successfully"); 
} 
3

ssteinberg的答案看起來還不錯,但也有這樣的:

NSRange textRange; 
textRange =[string rangeOfString:substring]; 

if(textRange.location != NSNotFound) 
{ 

//Does contain the substring 
} 

我發現here

2
NSString *string = @"hello bla bla"; 
if ([string rangeOfString:@"bla"].location == NSNotFound) 
{ 
    NSLog(@"string does not contain bla"); 
} 
else 
{ 
    NSLog(@"string contains bla!"); 
} 
1

ios 8或OS X 10.10我們可以使用。

if(![textLine containsString:@"abc"]) 
{ 
    [usableLines addObject:textLine]; 
} 
相關問題