はクイックフィックスとして、あなたはすべてのNSString
一部を必要はありません。この置換は、predicateWithFormat:
メソッドの全ポイントです!単純に次のコードを使用してください:
NSPredicate *query = [NSPredicate predicateWithFormat:@"s_name == %@ AND s_regno == %d", Name, [RegNo intValue]];
私は書式文字列を完全に避け、代わりにコードで述語を作成します。私はs_name like[cd] %@
のように、名前の大文字小文字と発音区別符号と小文字を区別しない比較を行うためにNSCaseInsensitivePredicateOption|NSDiacriticInsensitivePredicateOption
を追加
NSPredicate *nameQuery =
[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"s_name"]
rightExpression:[NSExpression expressionForConstantValue:Name]
modifier:NSDirectPredicateModifier
type:NSLikePredicateOperatorType
options:NSCaseInsensitivePredicateOption|NSDiacriticInsensitivePredicateOption];
NSPredicate *regNoQuery =
[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"s_regno"]
rightExpression:[NSExpression expressionForConstantValue:RegNo]
modifier:NSDirectPredicateModifier
type:NSEqualToPredicateOperatorType
options:0];
NSPredicate *query = [NSCompoundPredicate andPredicateWithSubpredicates:@[nameQuery,regNoQuery]];
注意。必要がない場合は、もちろんtype:NSEqualToPredicateOperatorType
とoptions:0
を使用できます。
あなたの入力文字列が二重引用符で囲まれている場合、何ですか? – northernman