views:

60

answers:

3

How to compare a string within a another string?

Example:

NSString *temp = @"english, french, japanese, chinese";
NSString *jap = @"japanese";

How do i compare the string "japanese" in temp with the string "japanese" in jap.

Is there any function?

Thanks in advance

A: 

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.

V1ru8
A: 

if([teststring isEqualToString:teststring2]==TRUE)

dosomethink();

A: 
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"); 
}
sugar