2011-05-07 112 views

回答

7
if ([myString rangeOfString:@"a"].location != NSNotFound) { 
    // "a" IS in myString 
} else { 
    // "a" ISN'T in myString 
} 

if ([myString rangeOfString:@"a"].location != NSNotFound && [myString rangeOfString:@"b"].location != NSNotFound) { 
    // "a" AND "b" are BOTH in myString 
} else if ([myString rangeOfString:@"a"].location != NSNotFound) { 
    // ONLY "a" is in myString 
} else if ([myString rangeOfString:@"b"].location != NSNotFound) { 
    // ONLY "b" is in myString 
} else { 
    // Neither "a" NOR "b" is in myString 
} 
+0

嗯...謝謝...讓我試試這個,並會讓你知道 – 2011-05-07 07:53:03

+0

以及如果我想嘗試它爲a和b?它是像@「a」,@「b」..就像那樣? – 2011-05-07 07:54:07

+0

我更新了我的帖子(也改變了前半部分)。告訴我,如果它不起作用。 – grc 2011-05-07 08:09:56

2
- (BOOL)isCharaterExist:(NSString *)sPhrase withSearchChar:(NSString *)sChar { 

     NSAssert(sPhrase != nil && sChar != nil, @"sPhrase and sChar should not be nil"); 

     return ([sPhrase rangeOfString:sChar].length > NSNotFound); 
} 

注:這不是在運行環境中測試,所以錯字錯誤可能是可能的!

+0

謝謝....黛米..和以上 – 2011-05-07 09:44:06

相關問題