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

}

}

}

}

}

相关推荐
c#上位机11 小时前
C#上位机项目实战——Task.Run执行带参数的方法
c#·上位机
Lost of 程序猿17 小时前
用 YARP 为 .NET 微服务搭一座“立交桥“:路由转发与生产配置实践
c#·asp.net
点纭20 小时前
C 语言 第七章 常用函数(3)
c语言·开发语言·算法·oracle·c#
用户7884773163420 小时前
用 .NET MAUI 一套 C# 同时出 Windows 和 Android:哪些是真能共享,哪些是 marketing
c#
Lost of 程序猿1 天前
用 Quartz.NET 优雅地处理 .NET 定时任务:从选型到 Docker 部署全记录
后端·c#·asp.net
林川~011 天前
Unity 万能物理检测工具:射线检测 / 范围检测 / 层级过滤 / 编辑器可视化(可直接拿去用)
游戏·unity·c#·射线检测·通用工具
He BianGu1 天前
【WPF-VisionMaster】机器视觉通用平台V5.0版本发行说明
opencv·c#·wpf·halcon·机器视觉·visionmaster
tang_04271 天前
【Hi.Ltd 专题】第9期:Interop 配置互操作(JSON/INI/XML/YAML/注册表/扫码)
经验分享·c#·hi.ltd系列
tang_04272 天前
【Hi.Ltd 专题】第7期:Threading 采集线程、锁与 LRU 缓存
经验分享·c#·hi.ltd系列
A_nanda2 天前
C# 界面卡顿:从定位到根治
c#