Blog

Compare text one character at a time in a code review

Find one-character code changes, including spaces, punctuation, and lookalike letters. Use a character-level diff, then verify each change in context.

Megan FosterTools and utilities 4 min read

A code review can show that a whole line changed without making the important detail clear. Maybe one letter changed, a space disappeared, or an operator gained an extra character. A character-level comparison helps you spot exactly what differs before you approve the change.

Use a text comparison or code review view that can highlight changes within a line. The names and controls vary between tools, so look for a character-level or inline comparison option rather than relying on a specific button name.

Compare the text character by character

  1. Open the original and revised versions of the same file or text in your code review view. Check that you are comparing the intended revisions, not two copies from different branches or saves.
  2. Switch the comparison to show changes within lines, if that option is available. A line-level view marks the whole line as changed, while a character-level view highlights the changed letters, spaces, or punctuation.
  3. Turn on visible whitespace if the comparison view supports it. Spaces, tabs, and line endings can look blank in the normal view, even when they are the only difference.
  4. Read each highlighted character together with the surrounding code. Check the full expression or identifier, then review nearby lines to see how the edit affects the program.

If your review view only marks whole lines, isolate the changed line in a text comparison feature that supports inline changes. Avoid copying text through a formatter before comparing it, because formatting can hide or introduce differences.

What the highlighted difference means

One letter or digit is highlighted

Check whether the edit changes an identifier, value, or name. Lookalike characters can be easy to miss, such as uppercase I and lowercase l, or the digit 0 and uppercase O. Compare the spelling with other uses of the same name in the file.

Punctuation is highlighted

A single punctuation mark can change how code behaves. For example, == and === are different operators in languages that support both. Check whether a bracket, quote, comma, or semicolon was added or removed, and confirm the result matches the intended logic.

A blank area or spacing mark is highlighted

The change may be a space, a tab, or a line ending. Whitespace can affect indentation-sensitive languages, string values, and shell commands. In other cases, the difference is only formatting. To investigate line-ending changes, see how to review line ending differences in a code review.

A whole line is marked despite a small edit

The comparison may be set to line-level changes, or nearby edits may have made it hard for the tool to align the text. Switch to an inline or character-level view if available. If it still marks the entire line, compare the shorter expression or value separately and keep the original code beside it for context.

How to review a suspicious difference

  1. Check the exact characters. Zoom in or widen the comparison pane so similar letters and punctuation are easy to distinguish. Do not judge a code change from a tiny preview.
  2. Make whitespace visible. Turn on the view's whitespace markers, if available, and check indentation and trailing spaces. Do not automatically remove whitespace before you understand whether it matters.
  3. Check the full expression. Read enough of the line to understand operator order, quotes, brackets, and the surrounding variable names. A highlighted character can change the meaning of more than the character itself.
  4. Look for related changes. Search the file or project for the identifier or value that changed. Check whether the new spelling is used consistently and whether the change is limited to the intended locations.
  5. Run the relevant checks. If the edit affects behavior, run the test or build that covers that code. A visual diff can show what changed, but it cannot prove that the change works correctly.

Why a one-character change can be hard to see

Some characters look alike at normal screen size. A font can make a zero resemble the letter O, or make a lowercase l resemble an uppercase I. If the distinction matters, compare the character at a larger size and check how the same character appears elsewhere in the code.

Visible letters can also be represented in different ways. For example, an accented character may be stored as one character or as a base letter followed by a separate accent mark. They can look identical while comparing differently. This is uncommon in many source files, but it can occur in strings, comments, names, and text data. If a visual comparison seems to show no change, check the exact underlying text or ask the author whether the characters were normalized.

Finally, a character-level diff shows where text differs, not whether the change is intentional, safe, or correct. Keep the code's purpose in view, and ask for clarification when a tiny change has no clear explanation.