Importing a string like “3d456…” as CSV crashes the kernel

 Importing a string like 3d456... as CSV crashes the kernel

I have a CSV file I’m importing with Import and it consistently crashes Mathematica. It turns out the culprit is one particular value of an ID field that was something like “3d456″ but with a bunch more numbers after the 456.

The problem becomes clear if you try to import that as CSV directly:

ImportString["3d456", "CSV"]

The output is a 3 followed by 456 zeros. In other words, it’s treating that string as a number in scientific notation. (Same thing if the “d” is an “e”, which would be the more common representation.)

This threw me for quite a loop. And Mathematica is doing this despite that ID being in double quotes in the actual CSV file, which seems wrong.

So I think the most general version of my question is: How do I ensure that fields in a CSV file that are in quotes get imported as strings?

Or other workarounds for not letting something like “3d456″ parse as a 457-digit integer.

Let’s block ads! (Why?)

Recent Questions – Mathematica Stack Exchange