如何设置google-diff-match-patch C#库

时间:2014-10-13 18:09:02

标签: c# visual-studio google-diff-match-patch

所以我是新手,我在互联网上找不到合适的答案。 在这里挖了一点之后就是我想出来的。

2 个答案:

答案 0 :(得分:2)

here

下载google-diff-match-patch

您已将其解压缩,打开您的微软视觉工作室项目

转到View-> Solution Explorer或按Ctrl + Alt + L

在解决方案资源管理器中右键单击项目名称,然后转到添加 - >现有项目...或按Shift + Alt + A

在出现的对话框中找到您的diff-match-patch文件夹并进入csharp目录并选择 DiffMatchPatch.cs 并单击Add

然后在解决方案资源管理器中右键单击References-> Add Reference ...

搜索System.Web并添加它。

现在回到你的程序(在我的例子中是Form1.cs)并输入

using DiffMatchPatch;

现在您已准备好在C#程序中使用diff-match-patch库的所有functions

答案 1 :(得分:0)

或者,添加Nuget包DiffMatchPatch并将其添加到您的项目中。

演示代码如下:

using System;
using System.IO;
using DiffMatchPatch;

namespace ConsoleApp_DMPTrial
{
     class Program
        {
            static void Main(string[] args)
            {
                var dmp = DiffMatchPatchModule.Default;

                string file1Content = "";
                string file2Content = "";

                using (StreamReader sr = new StreamReader("file1.json"))
                {
                    file1Content = sr.ReadToEnd();
                }

                using (StreamReader sr = new StreamReader("file2.json"))
                {
                    file2Content = sr.ReadToEnd();
                }

                var diffs = dmp.DiffMain(file1Content, file2Content);

                dmp.DiffCleanupSemantic(diffs);

                for (int i = 0; i < diffs.Count; i++)
                {
                    Console.WriteLine(diffs[i]);
                }

                Console.ReadLine();
            }
        }
}