简体   繁体   English

如何查找最小替换字符串或正则表达式以将字符串转换为另一个字符串

[英]How to find minimum replacement strings or regex to convert string to another string

Ok the title may be not correct but this is what i came as best 好的,标题可能不正确,但这就是我最好的结果

My question is this 我的问题是

Example 1 例子1

see , saw seesaw

I can convert see to saw with as 我可以转换seesaw有作为

replace ee with aw aw替换ee

        string srA = "see";
        string srB = "saw";

        srA = srB.Replace("aw", "ee");

Or lets say 或者说

show , shown showshown

add n to original string n添加到原始字符串

Now what i want it is, with minimum length of code, generating such procedures to any compared strings 现在我想要的是,以最小的代码长度,对任何比较的字符串生成此类过程

Looking for your ideas how can i make it? 寻找您的想法我怎么做? Can i generate regexes automatically to apply and convert? 我可以自动生成正则表达式以进行应用和转换吗?

c# 6 C#6

Check diffplex and and see if it is what you need. 检查diffplex ,然后查看它是否是您所需要的。 If you want to create a custom algorithm, instead of using a 3rd party library just go through the code -it's open source. 如果您要创建自定义算法,而不是使用第三方库,只需遍历代码-它是开源的。

You might also want to check this work for optimizations, but it might get complicated. 您可能还需要检查这项工作是否有优化,但是可能会变得很复杂。

Then there's also Diff.NET . 然后还有Diff.NET

Also this blog post is part of a series in implementing a diff tool. 此外, 此博客文章也是实现diff工具的系列文章的一部分。

If you're simply interested in learning more about the subject, your googling efforts should be directed to the Levenshtein algorithm . 如果您只是想了解更多有关该主题的知识,则应将搜索工作直接针对Levenshtein算法

I can only assume what your end goal is, and the time you're willing to invest in this, but I believe the first library should be enough for most needs. 我只能假设您的最终目标是什么,以及您愿意为此投入的时间,但是我相信第一个库应该足以满足大多数需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM