检查两个NSStrings是否相似 [英] Check if two NSStrings are similar

查看:130
本文介绍了检查两个NSStrings是否相似的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提出了一个棘手的问题,我不知道如何接近。所以,我制定了一个包含字典的plist,其中包含两个对象:

I present a tricky question that I am not sure how to approach. So, I have formulated a plist containing dictionaries which contain two objects:


  • 国家名称

  • 国家/地区的插头大小

虽然只有210个国家/地区。

There are only 210 countries/facts though.

而且,我已经搜索了许多国家的列表,其中可能有事实或不。但是这里是我的问题,我使用一个名为Geonames的Web服务,用户可以使用搜索栏显示控制器搜索国家,这些plist国家名称与插头大小配对实际上是从维基百科的文章。

And, I have enabled to search through a list of many many countries, in which there might be a fact or not. But here is my problem, I am using a web service called Geonames and the user can use a search bar display controller to search for countries, and these plist country names paired with plug sizes are actually from a Wikipedia article.

现在,Geonames和维基百科的plist中的国家命名可能会略有不同,可能有额外的空格,额外的破折号,额外的字母。这是为什么我想看看geoname国家字符串是否与plist中的字符串非常相似。

Now, the country naming in Geonames and in my plist from Wikipedia might be named slightly different, maybe with an extra space, an extra dash, an extra letter. This is why I want to see if the geoname country string is very similar to the one in the plist.

因此,这不会是 isEqualToString :因为它发现是否确切,比较:方法是否有效?

So, this would not be isEqualToString: because that finds if it is exact, can the compare: method work?

我该如何处理?下面是一个例子:

How can I approach this? Here is an example:

Geoname返回(不是一个真正的国家只是一个例子):

Geoname returns (not a real country just an example):


  • Yiting

但plist可能会传回:

But plist may return:


  • Yitting

有1个额外的't',但还有其他情况。我希望这些比较确切,或至少相似,所以我可以认为他们作为一个匹配。

So with 1 extra 't', but there are other circumstances. I would like these to be compared as exact, or at least similar, so I could consider them as a match.

有没有任何教程,资源,项目等你可以指点我?

Are there any tutorials, resources, projects etc. you could point me towards?

谢谢! Bye!

推荐答案

Soundex 算法在这种情况下很有用。

The Soundex algorithm is useful in cases like this.

我发现了一个示例实现在github上。

I found a sample implementation on github.

这篇关于检查两个NSStrings是否相似的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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