How to find difference between two strings?

不打扰是莪最后的温柔 提交于 2019-12-17 15:34:44

问题


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.)

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?


回答1:


Check this out: http://en.wikipedia.org/wiki/Diff#Algorithm

Also: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem

There is also an implementation described here: http://www.codeproject.com/KB/recipes/DiffAlgorithmCS.aspx



来源:https://stackoverflow.com/questions/208094/how-to-find-difference-between-two-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!