如何找到两个字符串之间的区别? [英] How to find difference between two strings?

查看:192
本文介绍了如何找到两个字符串之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个串,并想以显示它们之间的差异。举例来说,如果我有字符串我来自火星和我是来自金星,输出可以是我是从金星。 (通常用于显示审计日志什么改变,等等。)

I have two strings and would like to display the difference between them. For example, if I have the strings "I am from Mars" and "I am from Venus", the output could be "I am from Venus". (Typically used to show what changed in an audit log, etc.)

有一个简单的算法呢?我使用C#,但我想一个通用的算法,可以从任何编程语言进行调整。

Is there a simple algorithm for this? I am using C# but I guess a generic algorithm could be adapted from any programming language.

或者是有一个框架类/第三方库,会做这样的事情?

Or is there a framework class/third-party library that will do this sort of thing?

推荐答案

检查了这一点:<一href=\"http://en.wikipedia.org/wiki/Diff#Algorithm\">http://en.wikipedia.org/wiki/Diff#Algorithm

另外:<一href=\"http://en.wikipedia.org/wiki/Longest_common_subsequence_problem\">http://en.wikipedia.org/wiki/Longest_common_subsequence_problem

还有这里描述的实现:<一href=\"http://www.$c$cproject.com/KB/recipes/DiffAlgorithmCS.aspx\">http://www.$c$cproject.com/KB/recipes/DiffAlgorithmCS.aspx

这篇关于如何找到两个字符串之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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