2011-06-15 97 views
0
NSPredicate *predicate; 
predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS 'aaa'"]; 
BOOL result = [predicate evaluateWithObject:@"anystringaaaggg"]; 

結果爲true。但我需要創建一個包含「aaa」的NSString。我怎樣才能做到這一點?NSPredicate作爲字符串的結果

+0

你想添加「aaa」到現有的字符串嗎? – EmptyStack 2011-06-15 13:01:14

回答

1

不這樣工作。

例如,如何創建一個等於「Steve」或「Novikoff」的字符串?但你可以創建一個謂詞來檢查相同的條件。

0

你說上面的代碼的結果是True,所以你需要製作NSString對象。

NSPredicate *predicate; 
predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS 'aaa'"]; 
//this is for NSString object 
NSString *[email protected]"anystringaaaggg"; 
BOOL result = [predicate evaluateWithObject:checkMe]; 

然後我們可以使用這個checkMe作爲字符串對象,並在任何地方使用ü希望

OR

//other object 
id *checkMe=anyObject; 
BOOL result = [predicate evaluateWithObject:[NSString stringWithFormat:@"%@",checkMe]]; 
NSString *result=[checkMe stringValue]; 

然後,我們可以用這個結果作爲字符串對象,並在任何地方使用ü希望

相關問題