使用 Ruby 比较文本文件的两个版本并查找添加/删除内容?

发布于 2024-10-07 17:29:03 字数 158 浏览 0 评论 0原文

我正在使用 Ruby 跟踪网页中的更改。删除所有 html 标签和空行后,我得到了一个行数组,假设可能存在重复,需要检查这些行是否有添加/删除。如果已经完成了,您能推荐一个好的宝石吗?

我可以使阵列线唯一,然后问题就可以避免。但是,如果我还需要跟踪重复的行以及它们在文本中的位置怎么办?

I am tracking changes in a web-page using Ruby. After I removed all html tags and blank lines, I get an array of lines which needs to be checked for additions/removals assuming that there may be repetitions. Could you recommend a good gem if it has been done already?

I could make the array lines unique and then the problem is avoided. But what if I need to track the repeated lines as well with respect to their position in the text?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

腹黑女流氓 2024-10-14 17:29:03

听起来像是您想要使用 Diff 算法的教科书案例。

有一个“diff”gem,尽管公平地说我从未使用过它: http://rubygems.org/gems /差异

Sounds like a textbook case of where you'd want to use the Diff algorithm.

There's a 'diff' gem, although to be fair I've never used it: http://rubygems.org/gems/diff

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文