我阅读了org.apache.commons.text.diff
的文档。但我仍然不明白类 InsertCommand
、EditCommand
、KeepCommand
和 DeleteCommand
可以用来做什么。有人知道它们的全部内容以及如何使用它们吗?
最佳答案
如果比较两个字符串:
A B C E F H
(旧)
A C D E G H
(新)
那么你的“脚本”是:
Keep 'A'
Delete 'B'
Keep 'C'
Insert 'D'
Keep 'E'
Delete 'F'
Insert 'G'
Keep 'H'
如 EditCommand
的 javadoc 中所述:
When two objects sequences are compared through the
StringsComparator.getScript
method, the result is provided has ascript
containing the commands that progressively transform the first sequence into the second one.
关于java - org.apache.commons.text.diff 的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44834579/