gpt4 book ai didi

asp.net - Diffplex 入门

转载 作者:行者123 更新时间:2023-12-02 21:32:46 26 4
gpt4 key购买 nike

我想突出显示 asp.net 中两个文件之间的差异。经过网络搜索,我选择了 Diffplex APi。我是一个初学者。我需要一些关于如何实现它的指导?我已经添加了引用库,这就是我能理解的全部。没有任何 Api 文档。我以前没有使用过Apis。

最佳答案

这是“文档”(即源代码)中的一个简单示例,可以帮助您入门。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DiffPlex;
using DiffPlex.DiffBuilder;
using DiffPlex.DiffBuilder.Model;
using System.Text;


namespace DiffPlexTest.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
StringBuilder sb = new StringBuilder();

string oldText = @"We the people
of the united states of america
establish justice
ensure domestic tranquility
provide for the common defence
secure the blessing of liberty
to ourselves and our posterity";
string newText = @"We the peaple
in order to form a more perfect union
establish justice
ensure domestic tranquility
promote the general welfare and
secure the blessing of liberty
to ourselves and our posterity
do ordain and establish this constitution
for the United States of America";

var d = new Differ();
var builder = new InlineDiffBuilder(d);
var result = builder.BuildDiffModel(oldText, newText);

foreach (var line in result.Lines)
{
if (line.Type == ChangeType.Inserted)
{
sb.Append("+ ");
}
else if (line.Type == ChangeType.Deleted)
{
sb.Append("- ");
}
else if (line.Type == ChangeType.Modified)
{
sb.Append("* ");
}
else if (line.Type == ChangeType.Imaginary)
{
sb.Append("? ");
}
else if (line.Type == ChangeType.Unchanged)
{
sb.Append(" ");
}

sb.Append(line.Text + "<br/>");
}

ViewData["old"] = oldText;
ViewData["new"] = newText;
ViewData["result"] = sb.ToString();

return View();
}
}
}

关于asp.net - Diffplex 入门,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com