1
$\begingroup$

I generate simple txt file and import it as follows: a = Import["binary.txt"]; b = Import["binary.txt", "String"]. It appears then that lengths of imported strings a and b are quite different. But why?

$\endgroup$
  • $\begingroup$ that's how i generate the txt file, just in case: Export["binary.txt", ExportString[RandomReal[1000, 10], "Binary", "DataFormat" -> "Real32"]] $\endgroup$ – funnyp0ny Oct 31 '14 at 18:42
1
$\begingroup$
Import["binary.txt"]

in this case is equivalent to

Import["binary.txt", "Text"]

not to

Import["binary.txt", "String"]

Documentation states that Import["binary.txt"] "reads a text file, taking the character encoding to be "UTF8" by default." Whereas for format "String" documentation states that "imports a raw sequence of bytes and returns them as a Wolfram Language character string."

$\endgroup$
  • $\begingroup$ Thanks! Encoding really was the point, Import["binary.txt", CharacterEncoding -> "ASCII"] gives the same as "string". $\endgroup$ – funnyp0ny Oct 31 '14 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.