文本对比,DiffPlex

DiffPlex

下载地址:

http://diffplex.codeplex.com/

 

        /// <summary>
        /// 对比
        /// </summary>
        /// <param name="txt1">文本1</param>
        /// <param name="txt2">文本2</param>
        private void Comparer(RichTextBox txt1, RichTextBox txt2)
        {
            IDiffer diff = new Differ();
            DiffResult result = diff.CreateCharacterDiffs(txt1.Text, txt2.Text, false);
            foreach (DiffBlock item in result.DiffBlocks)
            {
                if (item.DeleteCountA > 0)
                {
                    txt1.Select(item.DeleteStartA, item.DeleteCountA);
                    txt1.SelectionBackColor = Color.Red;//红色为删除
                    txt1.SelectionFont = new Font(txt1.SelectionFont, FontStyle.Strikeout);//增加删除线
                }
                if (item.InsertCountB > 0)
                {
                    txt2.Select(item.InsertStartB, item.InsertCountB);
                    txt2.SelectionBackColor = Color.Yellow;//黄色为新增
                }
            }
        }

  

posted @ 2017-07-06 15:42  风中寻觅  阅读(788)  评论(0编辑  收藏  举报