Reputation: 33809
All diff tools I've found are just comparing line by line instead of char by char. Is there any library that gives details on single line strings? Maybe also a percentage difference, though I guess there are separate functions for that?
Upvotes: 10
Views: 3820
Reputation: 35306
You can implement a simple Needleman–Wunsch algorithm. The pseudo code is available on Wikipedia: http://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm
Upvotes: 3
Reputation: 114014
This algorithm diffs word-by-word:
http://github.com/paulgb/simplediff
available in Python and PHP. It can even spit out HTML formatted output using the <ins>
and <del>
tags.
Upvotes: 5
Reputation: 11438
I was looking for something similar recently, and came across wdiff. It operates on words, not characters, but is this close to what you're looking for?
Upvotes: 4
Reputation: 3364
What you could try is to split both strings up character by character into lines and then you can use diff on that. It's a dirty hack, but atleast it should work and is quite easy to implement.
Alternately you can split the string up into a list of chars in Python and use difflib. Check Python difflib reference
Upvotes: 3