如何使用C#比较两个RichTextBox文本 [英] How to compare two richtextbox text using C#
本文介绍了如何使用C#比较两个RichTextBox文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个逻辑来比较两个ricttext框的内容,但是输出差异文本未在预期索引处突出显示。它比预期的索引早开始。
I have written a logic to compare two ricttext boxes content, but the output difference text is not highlighted at the expected index. It starts ahead of the expected index. I have given below the logic i have used.
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;
}
}
感谢,
洛克什。
Thanks, Lokesh.
推荐答案
查找可能是问题的换行符
look for line feeds that may be the problem
这篇关于如何使用C#比较两个RichTextBox文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文