如何在字符串列表/数组中找到相似的模式 [英] How to find similar patterns in lists/arrays of strings

查看:41
本文介绍了如何在字符串列表/数组中找到相似的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在列表或字符串数​​组中查找匹配模式的方法,特别是在 .NET 中,但其他语言的算法或逻辑会有所帮助.

I am looking for ways to find matching patterns in lists or arrays of strings, specifically in .NET, but algorithms or logic from other languages would be helpful.

假设我有 3 个数组(或者在这种特定情况下为 List(Of String))

Say I have 3 arrays (or in this specific case List(Of String))

Array1
"Do"
"Re"
"Mi"
"Fa"
"So"
"La"
"Ti"

Array2
"Mi"
"Fa"
"Jim"
"Bob"
"So"

Array3
"Jim"
"Bob"
"So"
"La"
"Ti"

我想报告

("Mi", "Fa") In Arrays (1,2)
("So") In Arrays (1,2,3)
("Jim", "Bob", "So") in Arrays (2,3)
("So", "La", "Ti") in Arrays (1, 3)

...以及任何其他人.

...and any others.

我用它来解决问题,而不是专门制作它的商业产品,更不想手工制作(有 110 个列表,大约 100-200 个项目).

I am using this to troubleshoot an issue, not to make a commercial product of it specifically, and would rather not do it by hand (there are 110 lists of about 100-200 items).

是否有任何算法、现有代码或想法可以帮助我找到所描述的结果?

Are there any algorithms, existing code, or ideas that will help me accomplish finding the results described?

推荐答案

正如其他人提到的,你想要的函数是 Intersect.如果您使用 .NET 3.0,请考虑使用 LINQ 的 Intersect 函数.

As others have mentioned the function you want is Intersect. If you are using .NET 3.0 consider using LINQ's Intersect function.

请参阅以下帖子了解更多信息

考虑使用 LinqPAD 进行实验.

Consider using LinqPAD to experiment.

www.linqpad.net

这篇关于如何在字符串列表/数组中找到相似的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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