C# 如何找到两个字符串之间的差异?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/208094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 18:05:48  来源:igfitidea点击:

How to find difference between two strings?

c#stringword-diff

提问by

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.

有没有一个简单的算法?我正在使用 C#,但我想可以从任何编程语言中修改通用算法。

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

或者是否有一个框架类/第三方库可以做这种事情?