我有这个函数,我想比较两个字符串,然后返回存在多少个单词,但以下不起作用。我似乎总是得到 SameWordCount 的 0 和 MasterAddressWordCount 的 1
有任何想法吗?
// some more string cleaning
mastermkAddressKey = mastermkAddressKey.Replace(",", " ").Replace(".", " ").Trim();
mastermkAddressKey = Encoding.ASCII.GetString(Encoding.GetEncoding("Cyrillic").GetBytes(mastermkAddressKey));
mastermkAddressKey = mastermkAddressKey.Replace(" ", " |").Replace("| ", "").Replace("|", "");
mastermkAddressKey = QbaseStrings.RemoveDuplicateWords(mastermkAddressKey);
duplicatemkAddressKey = duplicatemkAddressKey.Replace(",", " ").Replace(".", " ").Trim();
duplicatemkAddressKey = Encoding.ASCII.GetString(Encoding.GetEncoding("Cyrillic").GetBytes(duplicatemkAddressKey));
duplicatemkAddressKey = duplicatemkAddressKey.Replace(" ", " |").Replace("| ", "").Replace("|", "");
duplicatemkAddressKey = QbaseStrings.RemoveDuplicateWords(duplicatemkAddressKey);
string[] masterAddressSeparateWords = mastermkAddressKey.Split(new char[' '], StringSplitOptions.RemoveEmptyEntries);
string[] duplicateAddressSeparateWords = duplicatemkAddressKey.Split(new char[' '], StringSplitOptions.RemoveEmptyEntries);
int SameWordCount = 0;
int MasterAddressWordCount = 0;
foreach (string masterWord in masterAddressSeparateWords)
{
foreach (string duplicateWord in duplicateAddressSeparateWords)
{
if (masterWord == duplicateWord) {SameWordCount++;}
}
MasterAddressWordCount++;
}
int WordDifference = MasterAddressWordCount - SameWordCount;
if (WordDifference == 0) { return "sure"; }
if (WordDifference > 0 && WordDifference < 3) { return SameWordCount.ToString() + " " + MasterAddressWordCount.ToString(); }
if (WordDifference > 2 && WordDifference < 5) { return "possible"; }