使用NSPredicate时出现问题 [英] Problem while using NSPredicate

查看:71
本文介绍了使用NSPredicate时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL查询:

从test_mart中选择*其中replace(replace(replace(replace(replace(replace(replace(lower(name),'+''

如果我只需要使用Sqlite,我可以很容易地触发以下查询...但是在当前项目中,我使用的是Core Data,因此对NSPredicate不太熟悉.

I can fire following query very easy, if I have to use simply Sqlite... but In current project I am using Core Data so not familiar about NSPredicate much.

该功能涉及删除所有BUT字母数字字符,这意味着删除特殊字符.

The functionality talks about removing all BUT alphanumeric characters, which means removing special characters.

在比较中应该有效的字符是

The characters that should be valid in the comparison would be

ABCDEFGHIJKLMNOPQRESTUVWXYZ1234567890

ABCDEFGHIJKLMNOPQRESTUVWXYZ1234567890

但是我们不应该对以下字符进行比较

But we should not fail the comparison for the following characters

:;; ~~!@#$%^& *()_- + ='/?.>,& lt; | \

:;,~`!@#$%^&*()_-+="'/?.>,<|\

或以下单词

'the''an''a'

'the' 'an' 'a'

一些例子:

  1. 沃尔玛"将被视为与沃尔玛"相同的收款人

  1. 'Walmart' would be seen as the same payee as 'Wal-Mart'

鞋店"将被视为与鞋店"相同的收款人

'The Shoe Store' would be seen as the same payee as 'Shoe Store'

多米诺比萨饼"将被视为与多米诺比萨饼"相同的收款人

'Domino's Pizza' would be seen as the same payee as 'Dominos Pizza'

任何人都可以建议合适的谓词/正则表达式吗?

Can any one suggest appropriate Predicates/Regular Expression ?

谢谢

推荐答案

我将在数据库中有一个额外的字段,该字段是原始内容的处理后的版本,其中删除了所有不相关的字符.然后将其用于比较.

I would have an extra field in the data base which would be a processed version of the original with all the irrelevant characters stripped out. Then use that for comparisons.

您可能想看一下能更好地满足您目的的soundex算法... Soundex

You might want to look at the soundex algorithm which may suite your purposes better... Soundex

这篇关于使用NSPredicate时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆