如何使用C#来显示文字的差异? [英] How to display word differences using c#?

查看:177
本文介绍了如何使用C#来显示文字的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示文本的两个街区之间的差异。而不是比较的文本或单个字符的线条,我想只是比较由指定的字符('\\\
','','例如\t')分隔。我给这家主要的理由是,我会比较一般不具备多换行符IT和字母比较可能很难执行的文本块。

I would like to show differences between two blocks of text. Rather than comparing lines of text or individual characters, I would like to just compare words separated by specified characters ('\n', ' ', '\t' for example). My main reasoning for this is that the block of text that I'll be comparing generally doesn't have many line breaks in it and letter comparisons can be hard to follow.

我遇到以下 O(ND)的逻辑在C#中用于比较的线条和文字,但我在如何修改它来比较的话损失是几分。

I've come across the following O(ND) logic in C# for comparing lines and characters, but I'm sort of at a loss for how to modify it to compare words.

另外,我想保持词之间的分隔符的轨道,并确保他们'再附带差异。因此,如果一个空间是由硬回车替换,我想,要拿出一个差异。

In addition, I would like to keep track of the separators between words and make sure they're included with the diff. So if a space is replaced by a hard return, I would like that to come up as a diff.

我使用Asp.Net(C#)显示包括删除原文,并添加新的文本文字的整个块(两者都将被突出显示,以表明它们已被删除/添加)。一个解决方案,这些技术将不胜感激工作。

I'm using Asp.Net (c#) to display the entire block of text including the deleted original text and added new text (both will be highlighted to show that they were deleted/added). A solution that works with those technologies would be appreciated.

任何意见,如何做到这一点表示赞赏。

Any advice for how to accomplish this is appreciated.

推荐答案

微软已经发布在CodePlex上一个diff项目,允许你做词,字符和线条的diff。它是在微软公共许可(MS-PL)许可。

Microsoft has released a diff project on CodePlex that allows you to do word, character, and line diffs. It is licensed under Microsoft Public License (Ms-PL).

https://github.com/mmanela/diffplex

这篇关于如何使用C#来显示文字的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆