DATA REPRESENTATION CHECKS

Inspecting tabs and newlines in ASCII text

A tab, a newline and a space can all look like empty gaps, yet each has its own ASCII code. This guide shows how to read the codes and tell the characters apart.

Invisible does not mean empty

Text on a screen is a sequence of characters, and some characters have no visible mark. A space leaves a gap, a tab moves to the next stop and a newline ends a line. To a reader they can look much alike, especially in copied text where line ends and tabs turn into spaces. To a program they are distinct values. A comparison of two strings, a parser splitting fields, or a search for a delimiter treats a tab and a space as different characters. Inspecting the numeric codes removes the guesswork about which one is present in a given piece of text.

What ASCII defines

ASCII, the American Standard Code for Information Interchange, assigns numbers 0 through 127 to characters. Codes 0 to 31 and 127 are control characters, and 32 to 126 are printable, with 32 being the space. The standard was first published in 1963 and revised several times afterward, and it is closely related to ISO/IEC 646. Its 7-bit design means every code fits in seven binary digits, and the common 8-bit byte leaves the top bit free. The control codes were designed for teleprinters and terminals, for instance horizontal tab at 9, line feed at 10 and carriage return at 13. Many of them are rarely used now, but tab, line feed and carriage return remain common in files and data.

The tab-separated example

The text A, tab, B encodes with the ASCII converter as 65 9 66. The letter A is 65, the letter B is 66, and the middle character, code 9, is the horizontal tab. Three characters give three codes, so the string is three bytes long in ASCII. A tab is one character, not a run of spaces, even though a viewer may draw it as a wide gap. Reading the middle code as 9 immediately tells you that the separator is a tab, which matters if a file format expects tabs as field delimiters. The tab-separated values format, used by spreadsheets and database exports, relies on exactly this character. A cell value that itself contains a tab breaks the column layout, and finding that stray 9 in the middle of a field is usually the fastest way to explain a row that has one column too many.

The space-separated example

The text A, space, B encodes as 65 32 66. The middle code 32 is the ordinary space, the first printable character in ASCII. The two strings look similar on many screens, particularly when a tab stop happens to land where a space would sit. Yet 65 9 66 and 65 32 66 are different, and a program that splits on spaces will not split the first string at all. Both strings occupy three bytes, but their contents differ, which is the point of the comparison.

Newlines and carriage returns

A line feed is code 10, and a carriage return is code 13. Text A, line feed, B encodes as 65 10 66. Windows text files commonly end lines with 13 followed by 10, so A, carriage return, line feed, B gives 65 13 10 66, four codes where Unix-style text gives three. The extra character is invisible in most editors and shows up as a stray symbol in some tools. When two files look identical but compare as different, a differing line-ending sequence is a frequent cause. Older Macintosh systems used a lone 13, which is a third convention. The codes for the three styles are 10 alone, 13 followed by 10, and 13 alone, and a file that mixes them can confuse tools that expect one style throughout. Reading the numbers settles which style a given file uses.

Other controls you may meet

Code 0 is the null character, which marks the end of a string in many programming languages. Code 27 is escape, which starts terminal control sequences, and code 127 is delete. Code 8 is backspace and code 7 is the bell. A copied block of text that misbehaves may contain one of these. A converter that lists the codes will show them as numbers while a display hides or misdraws them. The non-breaking space is not in this list at all, because it has no ASCII code. It belongs to extended sets and Unicode, where it is U+00A0.

Display width is not the code

A viewer can expand a tab across several screen columns, commonly up to the next multiple of 8 or 4, depending on the settings. That width describes how the tab is drawn and does not change that it is a single character with code 9. Two programs can show the same tab at different widths from the same byte. Alignment built from tabs therefore depends on the viewer, while alignment built from spaces depends on a fixed count. When exact separators matter, such as in tab-separated data, inspect the codes rather than judging the screen.

When to inspect codes

Check the codes when an import fails on a delimiter, when a string comparison says two visibly equal values differ, when a search misses text that is plainly there, or when a configuration file with strict whitespace rules rejects a line. A short sample is enough: encode a few characters around the problem spot and read the numbers. A 9 where a 32 was expected, or an extra 13, usually explains the failure. Fix the source so that it contains the intended character, then encode again to confirm. Printable characters deserve the same scrutiny when they look alike. The digit zero is 48 and the capital letter O is 79, and a lowercase l is 108 while the digit one is 49. In an identifier, a password field or a key copied from a document, one wrong code is enough to make a match fail, and the numbers show it at once.

What the ASCII view covers

The converter lists codes for the characters you supply and works for the 128 ASCII values. Text outside that range, such as accented letters or symbols, needs a wider encoding, and the byte count then differs from the character count. The tool does not clean, reformat or convert line endings. It reports what is present, which is the right basis for deciding what to change. Whether a tab, a space or a newline is correct depends on the format or program that will read the text.

Reproduce the checks

Tab-separated text

Open the Ascii Converter and enter:

Text or encoded input
A	B
Calculation mode
encode

Expected output:

Codes

65 9 66

The middle character is a tab.

Space-separated text

Open the Ascii Converter and enter:

Text or encoded input
A B
Calculation mode
encode

Expected output:

Codes

65 32 66

The middle code identifies an ordinary space.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Sources

Related tasks