Check if two NSStrings are similar
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:
- The Country Name
- The Plug Size Of The Country
There are only 210 countries/facts though.
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.
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.
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 returns (not a real country just an example):
But plist may return:
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?
Thank you! Bye!
3 Solutions Collect From Internet About “Check if two NSStrings are similar”
The Soundex algorithm is useful in cases like this.
I found a sample implementation on github.
You need to implement an algorithm for approximate matching of strings. One of the most popular such algorithms is Levenshtein distance, one of several Edit distance algorithms. The distance is calculated as the number of editing operations required to transform string A into string B – inserting, deleting, or changing a character counts as one edit operation. The closer are the strings, the smaller is the edit distance between them. You can calculate pairwise edit distances, and find the smallest one to identify the match.
You may find this post about auto update/complete useful:
I’ve tested that
UITextViews work well while adhering to the
UITextViewDelegate protocol in your UIViewController class and will produce a result similar to what you’ll find in the Messages app. I haven’t checked if
UITextFieldDelegate do as well.
- Sort an array of optional items that holds yet another optional
- Objective-C: Play Youtube Video on App
- What is a .a (as libcrypto.a) file?
- Unable to add a custom font in Mac app (OSX 10.9+ Xcode5+)
- NSTextField Vertical alignment
- Swift, sprite kit game: Have circle disappear in clockwise manner? On timer?
- What is the procedure for installing an external framework or library for Swift in XCode 6?
- Implementing -hash / -isEqual: / -isEqualTo…: for Objective-C collections
- Xcode Bot integration error : Failed to mmap
- – (void)applicationWillResignActive:(UIApplication *)application never gets called
- Are there examples of how to use UIPopoverController on iOS?
- using Facebook iOS SDK 2, how do I like a page? – “Application must be on whitelist”
- Objective c doesn't like my unichars?
- Disable App Nap in MacOS 10.9 (Mavericks) application
- How to write a background service in iphone application?