Today I am enabling a new section of my site to host my own projects. Its a bit rough but I will add to it in time. I am also releasing my first simple project stringDiff.
Recently I have been doing some work on oAuth for connecting to twitter and I found myself needing an easy way to highlight differences between two strings. What I wanted was to be able to input two strings and quickly see if they where different and what those differences where.
After some googling I did not find anything (written in cfml) so I wrote this simple component to do it for me. It worked out so well for me that I am making it available to download for anyone who might like it.
StringDiff takes two strings, a base string and a target string. It then compares every character in both strings to determine what changes are needed in the base string to convert it into the target string. The changes are then converted into an array of structs detailing the changes in order of execution.
For example comparing two string "helloworld" and "worldhello" will output an array of the following changes.
Additionally to the change array, there are two functions which can be used to format the change array as either a html string which colors changes or a html table.
To use stringDiff you call one of the three public methods passing in your baseString and targetString like this.
Note: I have included an init function but you can call the functions transiently if you so desire.
Base String: #string1#
Compare String: #string2#
#colorDiff#
#tableDiff#
Base String: #string1#
Compare String: #string2#
#colorDiff#
To learn more about stringDiff visit the projects page to demo or download it.