Niche Formats

Garbled characters in a CSV: repair the encoding

An export shows “Crème brûlée” or “Cr?me br?l?e”: drop the file, the tool guesses the encoding, repairs the text and returns a clean file.

Leave the detection on; change it only if accented letters are still wrong in the preview.

Why accented letters break

A text file does not say how its characters are encoded. A cash register saves in Windows-1252, an export page in UTF-8, an old Mac in Mac OS Roman. If the program that reads it guesses wrong, “é” becomes “é”. Worse, if that badly read text is saved again, the letters are damaged in the file itself: reading it as UTF-8 is no longer enough. The tool handles both cases: it chooses the encoding to read with, then detects and undoes text that was misread.

What the tool does, in order

  1. It looks for a byte order mark (UTF-8 or UTF-16), otherwise it tries strict UTF-8; a file that is not valid UTF-8 is read as Windows-1252, Mac OS Roman or ISO-8859-15, whichever gives the most plausible letters. You can force the encoding if the preview stays wrong.
  2. It spots the typical sequences of text that is already damaged (“é”, “’”, “” before a space) and repairs them, up to three times for a file damaged several times. Sound text that legitimately contains an “Ô is left alone.
  3. It reads the table (separator detected: semicolon, comma, tab or vertical bar; quotation marks and line breaks inside fields are understood).
  4. It writes a UTF-8 CSV with a byte order mark, with the separator you choose and, if you ask, with a comma or a dot as the decimal mark.

Limits to know about

A “?” or a box already written in the file (the original character was lost when it was saved) cannot be repaired: the information no longer exists, and the tool does not guess it. The automatic choice between Windows-1252 and ISO-8859-15 relies on the letters “œ” and “€”; when in doubt, force the encoding. The automatic choice between Windows-1252 and Mac OS Roman counts accented letters of Western European languages (French, Spanish, Portuguese, German, Scandinavian); for other alphabets, choose the encoding yourself. Numbers are changed only if they look like “12.5” or “12,5” alone in their cell; a version such as “v1.2” or a date is never converted.

Formula used and sources

Repair: each character of the damaged text is replaced by the Windows-1252 byte it decodes from, then the bytes are read again as UTF-8; the repair is kept only if the result is valid UTF-8.

Separator: the one that gives the most columns with a constant number of columns over the first rows.

Other tools on this site