If I have two longish strings, VARCHAR2s, is there a simple method or algorithm I can copy or port to PL/SQL to compare them, inserting markup (i.e. so that when rendered in a web page the differences will be highlighted).
For example:
BEGIN
DBMS_OUTPUT.put_line(
markup_differences
(in_old => 'Hello world, this is your captain speaking.'
,in_new => 'Hello WORLD, this is not your captain.'
,in_preins => '<ins>'
,in_postins => '</ins>'
,in_predel => '<del>'
,in_postdel => '</del>'
));
END;
Expected output:
Hello <del>world</del><ins>WORLD</ins>, this is <ins>not</ins> your captain
<del>speaking</del>.
Notice that this shows that "world' was changed to "WORLD", that "not" was inserted, and that "speaking" was removed.
Background: My intention is to compare two mostly-similar HTML fragments, and mark them up with highlights for display in a browser. Performance will not be a priority. This is for a throwaway app, so I'm not after a perfect solution. Even if something gets me part of the way there will be better than nothing - and I haven't promised anything to the client yet :)
Alternatively, a simple solution in Javascript that I can easily incorporate in my Apex application would be acceptable.
There is a really simple js-diff algorithm on John Resigs Blog: http://ejohn.org/projects/javascript-diff-algorithm/
Maybe that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With