本文介绍了不区分大小写的NSPredicate在CoreData中具有单个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我当前的NSPredicate:

  NSPredicate * predicate = [NSPredicate predicateWithFormat:@"UPC ==%@或ItemID ==%@",aUPCCode,aUPCCode]; 

如何使这种情况不区分大小写?

我不想做任何部分匹配.

例如,如果他们为aUPCCode输入123,我不想获取123、123a,123b,123c等.我只想要完全匹配.

我考虑过要这样做,但这似乎有点荒谬:

  NSPredicate * predicate = [NSPredicate predicateWithFormat:@"UPC ==%@或ItemID ==%@或UPC ==%@或ItemID ==%@或UPC ==%@或ItemID ==%@,aUPCCode,aUPCCode,[aUPCCode lowercaseString],[aUPCCode lowercaseString],[aUPCCode uppercaseString],[aUPCCode uppercaseString]]; 
解决方案

正如Dave DeLong所说,您可以使用:

  NSPredicate * predicate = [NSPredicate predicateWithFormat:@"UPC == [c]%@或ItemID == [c]%@",aUPCCode,aUPCCode]; 

修改:

使用 == [c] 代替 == [cd] ,否则也会得到重音符号( abcd ==àbcd)./p>

Here is my current NSPredicate:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"UPC==%@ OR ItemID==%@", aUPCCode,aUPCCode];

How can I make this case insensitive?

And I do not want to do any partial matching.

Example if they enter 123 for aUPCCode I do not want to get 123, 123a, 123b, 123c, ect. I would only want an exact match.

I thought about doing this but it seems a little ridiculous:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"UPC==%@ OR ItemID==%@ OR UPC==%@ OR ItemID==%@ OR UPC==%@ OR ItemID==%@", aUPCCode,aUPCCode,[ aUPCCode lowercaseString] ,[aUPCCode lowercaseString], [aUPCCode uppercaseString],[aUPCCode uppercaseString]];
解决方案

As Dave DeLong said, you can use:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"UPC ==[c] %@ OR ItemID ==[c] %@", aUPCCode,aUPCCode];

Edit:

Use ==[c] instead of ==[cd] or you get accents too (abcd == àbcd).

这篇关于不区分大小写的NSPredicate在CoreData中具有单个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 02:57