c# 使用DiffPlex 1.7.2进行内容对比实例

using DiffPlex.DiffBuilder;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using DiffPlex.DiffBuilder.Model;

using DiffPlex;

using DiffPlex.Model;

namespace WindowsFormsApp1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

string\[\] info = { "809Z39", "13587614965", "柳彦乐", "330302201403257318", "南浦小学", "四年级", "编程", "活泼好动" };

private void Form1_Load(object sender, EventArgs e)

{

string oldText = "这是第一段文本,用于比较。";

string newText = "这是第二段文本,包含了一些新增和删除的内容。";

Differ differ = new Differ();

// 使用 Differ 的 Compare 方法比较两段文本

DiffResult diff = differ.CreateCharacterDiffs(oldText, newText, true);

string del = "", add="";

// 遍历所有的差异项

foreach (DiffBlock item in diff.DiffBlocks)

{

if (item.DeleteCountA > 0)

{

del = oldText.Substring(item.DeleteStartA, item.DeleteCountA);

}

if (item.InsertCountB > 0)

{

add = newText.Substring(item.InsertStartB, item.InsertCountB);

}

}

}

}

}

相关推荐
kimloner7 小时前
开源一个 376KB 的 Windows 桌面小工具:便签 + 截图标注 + OCR + 待办提醒(C# / WinForms)
windows·开源·c#·ocr·winforms
阿松爱学习8 小时前
【Unity开发】Aspose.PDF的使用
unity·pdf·c#
半亩码田9 小时前
C#转Python第4.8篇:正则表达式:Python re 模块 vs C# System.Text.RegularExpressions
python·正则表达式·c#
FPGA小徐9 小时前
【一生一芯 / PA】异常响应机制:RISC-V 中 ecall → mtvec → mret 的完整代
开发语言·数据库·c#
淡海水10 小时前
02-04-原理篇-GC Roots与对象图遍历
算法·unity·c#·图·gc·遍历·roots
胖纸不争14 小时前
嫌桌面 Agent 太重,我“自己”写了一个
ai·c#·net core
当青春邂逅吉米多维奇18 小时前
C#图解教程(第5版) 同步方法
开发语言·c#
波力海苔夹心脆67518 小时前
C# 机器视觉实战:单相机引导机械手精准贴合,从拍照、偏差计算(平移+旋转)到坐标补偿全解
开发语言·经验分享·数码相机·c#·视觉检测·.net
Behavior21 小时前
国内下载使用 Unity 6000 踩坑点总结
c#·unity3d·游戏开发
czhc11400756631 天前
一张图从哪来,一个判断往哪走
c#