How to compare a string within a another string?
How to compare a string within a another string?
Example:
NSString *temp = @"english, french, japanese, chinese";
NSString *jap = @"japanese";
How do 开发者_JS百科i compare the string "japanese" in temp with the string "japanese" in jap.
Is there any function?
Thanks in advance
You wan't to check if the string temp
contains the string jap
? You can use the NSString method - (NSRange)rangeOfString:(NSString *)aString
. It returns you the range if it has found the aString in the receiver or a {NSNotFound, 0}
if nothing was found.
if([teststring isEqualToString:teststring2]==TRUE)
dosomethink();
NSString *temp = @"english, french, japanese, chinese";
NSString *jap = @"japanese";
NSRange foundObj=[temp rangeOfString:jap options:NSCaseInsensitiveSearch];
if(foundObj.length>0) {
NSLog(@"Yes ! Jap found");
} else {
NSLog(@"Oops ! no jap");
}
精彩评论