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