📋 文本比较

逐行对比两段文本,高亮显示差异

📊 比较结果

新增 删除 未变
请输入两段文本并点击"比较"

What Is Text Diff?

Text Diff (Text Compare) is the process of comparing two texts line by line and identifying their differences — which lines were added, removed, or remained unchanged. It is one of the most fundamental and important operations in software development, document management, and version control. Litekithub's Text Diff Tool is built on the classic Longest Common Subsequence (LCS) algorithm and efficiently computes and highlights differences between two texts.

Core Algorithm: Longest Common Subsequence (LCS)

This tool uses the classic LCS dynamic programming algorithm to compute text differences. Here's how it works:

  1. Line-level Dynamic Programming: Split both texts into lines and build an (m+1)×(n+1) DP table, where m and n are the line counts of the two texts.
  2. LCS Computation: Compute the longest common subsequence length matrix via dynamic programming. If two lines match, dp[i][j]=dp[i-1][j-1]+1; otherwise, take the maximum of dp[i-1][j] and dp[i][j-1].
  3. Backtracking for Diffs: Backtrack from the bottom-right to the top-left of the DP table, marking each line as "unchanged," "added," or "removed."
  4. Formatted Presentation: Render the backtracking result as a clear two-column table with line numbers, using green backgrounds for added lines and red backgrounds for removed lines.

This LCS-based approach produces an optimal diff result, minimizing the number of added/removed lines and maximizing the recognition of reused content.

Feature Details

Line-by-Line Comparison

The tool splits both texts by line and compares them line by line. Using the LCS algorithm, it precisely identifies the correspondence of each line between the original and modified texts. The result is displayed as a dual-column line number table, with original text line numbers on the left and modified text line numbers on the right, making it easy to quickly locate differences.

Visual Color Coding

Diff results use an intuitive color coding scheme:

  • 🟢 Green Rows: Marked as "Added" — these lines only exist in the modified text.
  • 🔴 Red Rows: Marked as "Removed" — these lines only exist in the original text.
  • ⚪ White Rows: Marked as "Unchanged" — these lines exist in both texts with identical content.

Statistical Summary

After each comparison, the tool displays a statistical summary at the top of the results, showing the count of added lines, removed lines, and unchanged lines. This gives you a quick overview of the overall difference magnitude between the two texts.

Swap Function

Swap the positions of the original and modified texts with one click, automatically re-running the comparison. This is useful when you want to view differences from the opposite direction — for example, switching from an "old→new" comparison to a "new→old" comparison.

Keyboard Shortcuts

Use the Ctrl+Enter keyboard shortcut to trigger the comparison quickly, allowing you to compare text without taking your hands off the keyboard.

Typical Use Cases

  • Code Review: Compare before-and-after versions of code to quickly identify changes.
  • Document Version Comparison: Review changes in articles, contracts, and agreements.
  • Config File Change Tracking: Compare different versions of server configuration files.
  • Translation Proofreading: Compare structural differences between source and translated texts.
  • Data Comparison: Compare changes in structured text such as CSV and log files.

Why Choose Litekithub's Text Diff Tool?

Litekithub's online text diff tool offers the following advantages:

  • Classic LCS Algorithm: Built on the dynamic programming Longest Common Subsequence algorithm, producing optimal diff results.
  • Dual-Column Diff View: Clear line number markers and color distinction — differences are visible at a glance.
  • 100% Local Processing: All text is processed locally in your browser — nothing is ever uploaded to any server, ensuring data security.
  • Ready to Use: No installation required — just open your browser.
  • Preloaded Example: Code examples are automatically loaded on page launch for quick feature exploration.

No registration, no installation, completely free. An essential tool in every developer's, document author's, and data analyst's toolkit.