我需要做一个字一个字的比较两个串。什么样的差异,但是对话,而不是进行。

喜欢它是在维基百科 http://en.wikipedia.org/w/index.php?title=Horapollo&action=historysubmit&diff=21895647&oldid=21893459

在此,我希望返回的两个阵列的索引的话,这是不同的两个串。

是否有任何库/frameworks/standalone_methods。净其可以这样做?

P.S.我想来比较几个千字节的文本

有帮助吗?

解决方案 2

看来我已经找到所需的解决方案:

DiffPlex是一个.NET版本比较库的同时具有Silverlight和HTML差异阅读器的组合。 http://diffplex.codeplex.com/

,但它有一个错误。在这些线路的“Hello-Kitty的”“你好 - 小鹰”,单词“你好”将被标记为差。虽然不同的是空间符号。

其他提示

其实,你可能想实现的,我们在DNA 序列使用局部对齐/全球校准算法的变化路线的。这是因为你可能做不到这两个字符串的字的字比较。即:

  

快速褐色狐狸跃过   懒狗结果   快速狐狸跃过   惰性狗

在换句话说,如果你不能确定插入和整词删除,你的比较算法可能会变得非常SC(R)ewed。看看在史密斯 - 沃特曼的算法和尼德曼 - 翁施的算法,并找到一种方法,使其适应您的需求。因为这样的搜索空间会变得非常大,如果字符串很长,你也可以检查出BLAST。 BLAST是一种很常见的启发式算法,并且是几乎在遗传搜索标准。

使用RegularExpressions。

像中的示例:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections.Specialized;

namespace WindowsApplication10
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            decimal discrimation = 0.75M;
            string formHeading = "The brown dog jumped over the red lazy river, and then took a little nap! Fun!";
            string userSearch = "The brown dog jumped over the red lazy river, and then took a little ";
            //string userSearch = "brown dog nap fun";
            decimal res = CompareText(formHeading, userSearch);

            if (res >= discrimation)
            {
                MessageBox.Show("MATCH!" + res.ToString());
            }
            else 
            {
                MessageBox.Show("does not match! " + res.ToString());
            }
        }


        /// <summary>
        /// Returns a percentage of 1 on how many words were matched
        /// </summary>
        /// <returns></returns>
        private decimal CompareText(string formHeading, string userSearch)
        {
            StringCollection formHeadingWords = new StringCollection();
            StringCollection userSearchWords = new StringCollection();
            formHeadingWords.AddRange(System.Text.RegularExpressions.Regex.Split(formHeading, @"\W"));
            userSearchWords.AddRange(System.Text.RegularExpressions.Regex.Split(userSearch, @"\W"));

            int wordsFound = 0;
            for (int i1 = 0; i1 < userSearchWords.Count; i1++)
            {
                if (formHeadingWords.Contains(userSearchWords[i1]))
                    wordsFound += 1;
            }
            return (Convert.ToDecimal(wordsFound) / Convert.ToDecimal(formHeadingWords.Count));
        }
    }
}

您可以取代所有的话在你的2个文本具有独特的编号,采取编辑距离计算一些现成的代码,并将其的性格与数数比较字符比较,就大功告成了!

我不知道是否有存在ü想要什么任何库。但是,你一定会发现很多的代码编辑距离。

此外,取决于是否要实际上要允许取代或未在编辑距离计算,可以改变条件在动态编程代码。

请参阅此。 http://en.wikipedia.org/wiki/Levenshtein_distance

您可以试试这个,虽然我不知道这是你在找什么StringUtils.difference()(的 http://commons.apache.org/lang/api-release/org/阿帕奇/公地/郎/ StringUtils.html#差%28java.lang.String,%20java.lang.String%29

或者,在Eclipse(eclipse.org)项目具有差异比较功能,这意味着他们还必须有代码,以确定这些差异,可能需要通过他们的API或浏览来源,看看你能发现什么。

好运。

为C#还有一个库是DIFF-匹配贴片 - HTTP:/ /code.google.com/p/google-diff-match-patch/

在坏事它发现字符的区别。好在,有指令,你有什么要添加到差异的话。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top