问题描述
我正在为一个游戏做一个聊天响应者,我想知道是否有一种方法可以比较两个字符串,看看它们是否大致相等,例如:
I'm making a chat responder for a game and i want know if there is a way you can compare two strings and see if they are approximatley equal to each other for example:
如果有人打字:
力量等级?
它会做一个函数..
然后如果有人打字:
Str level?
它会做同样的功能,但我想要它,以便如果有人做了一个拼写错误或类似的事情,它会自动检测他们想要输入的内容,例如:
Strength tlevel?
也会调用该函数。
if someone typed: "Strength level?"it would do a function..then if someone else typed: "Str level?"it would do that same function, but i want it so that if someone made a typo or something like that it would automatically detect what they're trying to type for example: "Strength tlevel?"would also make the function get called.
我在这里问的是一些简单的东西还是需要我做一个巨大的刺激性功能来检查字符串?
is what I'm asking here something simple or will it require me to make a big giant irritating function to check the Strings?
如果你对我的解释感到困惑(不是我的强项之一)那么这基本上就是我所要求的。
if you've been baffled by my explanation (Not really one of my strong points) then this is basically what I'm asking.
如何判断两个字符串是否相似?
How can I check if two strings are similar to each other?
推荐答案
参见这个问题和答案:
See this question and answer: Getting the closest string match
使用一些启发式算法和算法,你可以计算两个字符串的相似性,并猜测它们是否相等。
Using some heuristics and the Levenshtein distance algorithm, you can compute the similarity of two strings and take a guess at whether they're equal.
除此之外,您唯一的选择是与您正在寻找的词语类似的词典。
Your only option other than that would be a dictionary of accepted words similar to the one you're looking for.
这篇关于如何检查两个字符串是否大致相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!