开发者

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"); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜