Skip to main content

import - Why does ImportString["1c", "Table"] eat the letter c?


I have some whitespace-separated matrix data that I read with Import[..., "Table"]. The data contained mixed strings and numbers (the strings are for row and column names).



I noticed this weird behaviour:


ImportString["123c", "Table"]

(* ==> {{123}} *)

Mathematica ate the letter c!! Why?


It doesn't eat any other letters:


ImportString["123a", "Table"]
(* {{"123a"}} *)


ImportString["123e", "Table"]
(* {{"123e"}} *)

What is the explanation and what is a good workaround?




Update:


It seems that this happens even if the labels is quoted in the file:


ImportString["\"24c\"", "CSV"]

(* ==> {{24}} *)


Answer



Mathematica is interpreting c as a currency marker. This is controlled by the "CurrencyTokens" import option for "Table".


The default setting for "CurrencyTokens" is


{{"$ ", "£", "¥", "€"}, {"c ", "¢", "p ", "F "}}

so this also happens with the letters p or F.


The workaround is


ImportString["123c", "Table", "CurrencyTokens" -> None]
(* {{"123c"}} *)


Notice: The same applies to the "CSV", "TSV" and "List" import formats.


Comments