Text Diff: LCS Algorithm and Diff Export

Open Tool Text Compare

How line comparison finds differences

The classic approach is the longest common subsequence: split both texts into lines, find the longest ordered match, and the remaining lines are additions and deletions. The tool compares line by line, marking lines only on the left, only on the right, and on both. Controls compare, load a sample, clear, copy differences and download a diff. Statistics report added and removed counts, and the exported diff text is readable by version tools.

Steps

  1. Paste the old version on the left and the new on the right, keeping line structure.
  2. Load the sample to check highlighting and confirm left-right order.
  3. Compare and inspect the positions and counts of highlighted lines.
  4. Reconcile statistics with expectations.
  5. Copy differences into a ticket, or download the diff for records.
  6. Clear to restart, noting both panes empty.

Line-level versus character-level

Line comparison treats each line as a unit, so one changed word marks the whole line: stable and readable but coarse. Character comparison pinpoints words but adds noise that long lines make unreadable. LCS cost scales with the product of lengths, slowing on long texts that benefit from splitting first. Whitespace handling matters, since spaces replaced by tabs mark everything changed. Different line endings also flag whole documents, so unify them beforehand. Standard diff format marks left and right versions with angle brackets and is readable by most patch tools.

Common mistakes

Swapping the panes and inverting the reading. Leaving whitespace differences to flag everything. Mixed line endings producing false changes. Comparing very long texts without splitting. Judging scope from highlights alone. And exporting diffs without version labels.

Where a two-way diff stops

Three-way merges need version control. Tables compare by column, not line. Binary files need hex comparison. And line-level views deserve character-level inspection for precise review.

⏫︎