使用 Ruby 比较文本文件的两个版本并查找添加/删除内容?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来像是您想要使用 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