比较两个 NSString 的相似度 [英] Compare similarity of two NSStrings
问题描述
我想比较两个 NSString
.如果用户输入巨石阵",应该得到一个答案边界"=几乎等于",因为正确的答案是:巨石阵".
I would like to compare two NSString
s. If the user types "Stonehhengge", should get a "border on answer"="almost equals", because the right answer is: "Stonhenge".
我想要一个字符串等于另一个字符串的百分比.如果巨石阵"是 9 个字母,并且输入的文本包含来自巨石阵"的 8 个字母,但它不等于巨石阵",例如:巨石阵"不等于巨石阵",但它接近 - 我会想知道字符串的匹配程度.
I would like a percentage of how much one string equals another. If "Stonhenge" is 9 letters, and the typed text contain 8 letters from "Stonhenge", but it's not equal to "Stonhenge", for example: "Stonehange" is not equal to "Stonhenge", but it's near - I'd like to know how near a match the strings are.
我只知道 isEqual:
.如果您输入巨石阵",您将匹配并获得正确的符号.如果文本字段的文本不相等,则不会得到匹配并得到错误的符号.
I only know isEqual:
. If you type "Stonehenge", you match and will get the right symbol. If text field's text is not equal, you do not get a match and get the wrong symbol.
推荐答案
编辑您想要计算 Levenshtein 距离.
您可能想查看这个问题 计算两个 NSStrings 之间的差异数
You may want to check out this question Calculate number of differences between two NSStrings
这篇关于比较两个 NSString 的相似度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!