GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - javalc6/stringdiff2: A java application that highlights text differences between two plain strings based on longest common subsequences

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
StringDiff2.java
StringDiff2.java
 
 
diff_html_rendering.png
diff_html_rendering.png
 
 

Repository files navigation

StringDiff2

This java application highlights text differences between two plain strings by generating html fragment to show changes, based on longest common subsequences.

The markTextDiff2() markups changes between text1 and text2 using the longestCommonSubsequence() method.

The Hirschberg algorithm provides Longest Common Subsequence using a linear amount of memory.

Java 8 or later is required to run the application.

Compile

Run following command to build the application:

javac StringDiff2.java

Run

Just use the following command to run the application:

java StringDiff2

Example

Setting the following strings:

text1 = "Do not change this section. Please check any misqelling! Note that this section is obsolete.";
text2 = "New section added. Do not change this section. Please check any mispelling!";

running the command "java StringDiff2" will generate the following html fragment:

<ins style='background-color:#00ff66'>New section added. </ins>Do not change this section. Please check any mis<del style='background-color:#ff9933'>q</del><ins style='background-color:#00ff66'>p</ins>elling!<del style='background-color:#ff9933'> Note that this section is obsolete.</del>

If you load the html fragment with a browser, you get the following result:

html fragment in a browser

Credits

The java implementation of the longest common subsequence Hirschberg algorithm is credited to https://commons.apache.org/proper/commons-text/index.html

Caveat

This algorithm has O(n * m) complexity. In case of very long strings it is very slow.

About

A java application that highlights text differences between two plain strings based on longest common subsequences

Topics

compare-stringscompare-textjavastring-comparestring-comparisonstring-differencesstringstext-comparetext-comparisontext-diff

Resources

Readme
GPL-2.0 license
Activity

Stars

3 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.