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

}

}

}

}

}

相关推荐
她说彩礼65万1 天前
C# 特性详解
linux·服务器·c#
她说彩礼65万1 天前
C# AutoResetEvent和ManualResetEvent
java·jvm·c#
5967851541 天前
C# 弹出框DialogForm
开发语言·c#
聪明努力的积极向上1 天前
【C#】System.Text.Encoding.Default 属性在framework和.netcore中的区别
开发语言·c#·.netcore
数据的世界011 天前
编程语言排行榜2025年11月
c#·.net
yongshao81 天前
KUKA机械臂使用EthernetKRL配置与C#上位机实现TCP通讯
tcp/ip·机器人·c#·信息与通信
·心猿意码·2 天前
C# 垃圾回收机制深度解析
开发语言·c#
唐青枫2 天前
C#.NET 开发必备:常用特性与注解用法大全
c#·.net
好望角雾眠2 天前
第四阶段C#通讯开发-5:TCP
网络·笔记·网络协议·tcp/ip·c#
InCerry2 天前
.NET周刊【11月第1期 2025-11-02】
c#·.net周报·.net周刊