我有以下代码:
public static int Compute(string a, string b, bool ignoreCase)
{
// Allocate distance matrix
int[,] d = new int[a.Length + 1, b.Length + 1];
// Get character comparer
CharComparer isEqual = (ignoreCase) ?
(CharComparer)CharCompareIgnoreCase : CharCompare;
// Compute distance
for (int i = 0; i <= a.Length; i++)
d[i, 0] = i;
for (int j = 0; j <= b.Length; j++)
d[0, j] = j;
for (int i = 1; i <= a.Length; i++)
{
for (int j = 1; j <= b.Length; j++)
{
if (isEqual(a[i - 1], b[j - 1]))
{
// No change required
d[i, j] = d[i - 1, j - 1];
}
else
{
d[i, j] =
Math.Min(d[i - 1, j] + 1, // Deletion
insertions= Math.Min(d[i, j - 1] + 1, // Insertion
substitutions= d[i - 1, j - 1] + 1)); // Substitution
}
}
}
关键位在底部带有注释删除,插入和替换,我想知道如何在其上添加变量增量器,以便每次检测到删除错误时变量增加一。我试过了:
{ d[i, j] =
deletion= Math.Min(d[i - 1, j] + 1, // Deletion
insertions= Math.Min(d[i, j - 1] + 1 + insertion ++, // Insertion
substitutions= d[i - 1, j - 1] + 1)); // Substitution
}
但只是没有运气