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

}

}

}

}

}

相关推荐
一名用户3 小时前
unity实现梦日记式传送组件
后端·c#·unity3d
阿蒙Amon4 小时前
C#扩展方法全解析:给现有类型插上翅膀的魔法
开发语言·c#
江山如画,佳人北望18 小时前
C#程序入门
开发语言·windows·c#
与火星的孩子对话19 小时前
Unity进阶课程【六】Android、ios、Pad 终端设备打包局域网IP调试、USB调试、性能检测、控制台打印日志等、C#
android·unity·ios·c#·ip
future141219 小时前
C#每日学习日记
java·学习·c#
军训猫猫头1 天前
1.如何对多个控件进行高效的绑定 C#例子 WPF例子
开发语言·算法·c#·.net
葬歌倾城2 天前
JSON的缩进格式方式和紧凑格式方式
c#·json
Eiceblue2 天前
使用 C# 发送电子邮件(支持普通文本、HTML 和附件)
开发语言·c#·html·visual studio
小小小小王王王2 天前
hello判断
开发语言·c#
金增辉2 天前
基于C#的OPCServer应用开发,引用WtOPCSvr.dll
c#