我已經寫了一個邏輯比較兩個ricttext箱內容,但差輸出文本沒有在預期的指數突出比較兩個RichTextBox的文本。它在預期指數之前開始。我在下面給出了我用過的邏輯。如何使用C#
private void CompareRichTextContents(RichTextBox target, RichTextBox dest)
{
string[] targetLines = target.Lines;
string[] destLine = dest.Lines;
List<string> result=targetLines.Except(destLine).ToList<string>();
foreach (string str in result)
{
int lineIndex=Array.IndexOf(targetLines, str);
int lineCount=0;
for (int index = 0; index < lineIndex; index++)
{
lineCount+=targetLines[index].Length;
}
target.SelectionBackColor = Color.Yellow;
target.SelectionColor = Color.Black;
target.SelectionStart = lineCount;
target.SelectionLength = str.Length;
}
}
謝謝, Lokesh。
哪條線它凸顯,到底是什麼? – MGZero
例如,我有下面線路目標部分: <尺寸REF = 「C2」/> DestPart 行應該從尺寸被突出顯示,但它也會從開始「/ >「來自上一行 –
Lokesh