[英]Search for Specific String in another String
我正在使用此代碼段在另一個String中搜索一個String。 如果第一個if可以正常工作,但是如果第二個單詞僅在我搜索兩個單詞時返回YES(true),則在第二個之后工作(如果要搜索的單詞從第一個單詞開始,則返回YES(true))
如果假設包含: "OPEN TWITTER"
則有效,如果假設為"PLEASE OPEN TWITTER"
,則無效
if ([hypothesis rangeOfString:@"OPEN"].location == !NSNotFound) {
NSLog(@"hypothesis contains OPEN");
if ([hypothesis rangeOfString:@"OPEN TWITTER"].location == !NSNotFound) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"twitter://"]];
}
if ([hypothesis rangeOfString:@"OPEN FACEBOOK"].location == !NSNotFound) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"fb://"]];
}
}
我希望它在字符串中還有其他單詞時也能起作用,我只想使其在字符串中的某個位置擊中關鍵字,然后返回YES(以確定“假設”包含單詞,然后執行操作)
== !NSNotFound
應該更改為
!= NSNotFound
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.