Using C#, how can I replace similar words?

后端 未结 5 2054
孤城傲影
孤城傲影 2021-02-04 17:26

Assuming these two strings:

string s1=\"control\";
string s2=\"conrol\"; (or \"ocntrol\", \"onrtol\", \"lcontro\" etc.)

How can I programatical

相关标签:
5条回答
  • 2021-02-04 17:46

    I'll Suggest a simpler answer. Compare the length of the 2 strings & also compare the sum of ASCII values of the both strings.

    0 讨论(0)
  • 2021-02-04 17:57

    Linq Method: Try to store the chars in both the strings in two List<chars> or List<String> and compare (SequenceEqual or Except) the samller one with the bigger one.

    0 讨论(0)
  • 2021-02-04 18:05

    You can use Levenshtein Distance which would give you a rank on how close the two words are. You need to decide at which rank you do the replace .

    0 讨论(0)
  • 2021-02-04 18:06

    I'd use matlab to run some tests on this. I would do the follow

    CONTROL 1111111

    OCNTROL 0011111

    ONRCTOL 0000111

    So I have all 1s for original word, than I have five 1s in a second case and three 1s in a third. You can say that 70% is acceptable and if 70% match than I will use this word. OCNTROL will get accepted, but ONRCTOL won't.

    I say Matlab because you can easily load a lot of data into vectors and do vector comparissons.

    0 讨论(0)
  • 2021-02-04 18:11

    You could try to check the Levenshtein distance between your two words and if the distance is beyond a threshold, replace the word.

    The hard part is defining the threshold, in your examples a threshold of 2 could work.

    (Implementation of Levenshtein distance in C#)

    0 讨论(0)
提交回复
热议问题