How to check if two Strings are approximately equal?

前端 未结 6 2006
醉酒成梦
醉酒成梦 2021-02-04 05:30

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:

6条回答
  •  鱼传尺愫
    2021-02-04 05:56

    Perhaps what you need is a large dictionary for similar words and common spelling mistakes, for which you would use for each word to "translate" to one single entry or key.

    This would be useful for custom words, so you could add "str" in the same key as "strength".

    However, you could also make a few automated methods, i.e. when your word isn't found in the dictionary, to loop recursively for 1 letter difference (either missing or replaced) and can recurse into deeper levels, i.e. 2 missing letters etc.

提交回复
热议问题