NSPredicate字符和/或字母替换 [英] NSPredicate Character and/or Letter Substitutions

查看:189
本文介绍了NSPredicate字符和/或字母替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到一些,有点,类似的问题,过滤掉一个谓词中的特殊字符,但没有什么适合我的需要。我不太确定我想做什么是可能的,但我会把它交给社区:

I've seen some, somewhat, similar questions about filtering out special characters in a predicate - but nothing suitable for my needs. I'm not really sure if what I want to do is even possible but I'll put it to the community instead:

我正在使用发音字符串包含大量IPA字符的字典,例如:
ȵ
ɕ
ŋ

I'm working with strings of pronunciations for a dictionary that contain a lot of IPA characters for instance: ȵ ɕ ŋ Ẓ

喜欢做的是为这些字符设置一些替换,例如:
n =ȵ
x =ɕ
ng =ŋ
r =Ẓ

What I would like to do is set up some substitutions for these characters, something like: n=ȵ x=ɕ ng=ŋ r=Ẓ

在搜索谓词中,以便搜索n *将导致任何以ȵ,等等开头的内容...

in a search predicate so that a search for n* would result with anything beginning in ȵ, etc, etc...

甚至其他IPA的字母如果有一个简单的方法切换到其他STRING字母的搜索字母,这将是很好的...v最好类似于w...

Even other IPA 'letters' like "v" would be best resembled by a "w" if there is a simple way to switch in SEARCH letters for other STRING letters that would be great...

推荐答案

看起来这应该在谓词外做。创建一个字典,其中键是要替换的字符串,值是替换字符串。然后,有一个循环遍历字典,并对要搜索的字符串执行每个替换。替换后生成的字符串是您在谓词中使用的字符串。

It seems like this should be done outside the predicate. Create a dictionary where the keys are the strings to be replaced and the values are the replacements. Then, have a loop which iterates over the dictionary and performs each replacement on the string that you will be searching. The resulting string after replacement is the string that you use in the predicate.

这篇关于NSPredicate字符和/或字母替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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