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);

}

}

}

}

}

相关推荐
世洋Blog22 分钟前
SiYangUnityEventSystem,一个Unity中的事件系统
观察者模式·unity·c#·游戏引擎·事件系统
切糕师学AI1 小时前
如何用 VS Code + C# Dev Kit 创建类库项目并在主项目中引用它?
开发语言·c#
William_cl1 小时前
【CSDN 专栏】C# ASP.NET控制器过滤器:自定义 ActionFilterAttribute 实战(避坑 + 图解)
c#·asp.net·状态模式
William_cl2 小时前
【CSDN 专栏】C# ASP.NET Razor 视图引擎实战:.cshtml 从入门到避坑(图解 + 案例)
开发语言·c#·asp.net
isyoungboy2 小时前
c++使用win新api替代DirectShow驱动uvc摄像头,可改c#驱动
开发语言·c++·c#
技术支持者python,php2 小时前
USB摄像头采集数据
人工智能·c#
c#上位机14 小时前
halcon刚性变换(平移+旋转)——vector_to_rigid
图像处理·人工智能·计算机视觉·c#·halcon
Miss_SQ14 小时前
Webgl打包后删除StreamingAssets文件夹下多余资源
unity·c#·webgl
小猪快跑爱摄影14 小时前
【AutoCad 2025】【C#】零基础教程(二)——遍历 Entity 插件 =》 AutoCAD 核心对象层级结构
开发语言·c#·autocad
烛阴15 小时前
C# Dictionary 入门:用键值对告别低效遍历
前端·c#