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

1 Answer 1

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$
1
  • $\begingroup$ Thanks! Encoding really was the point, Import["binary.txt", CharacterEncoding -> "ASCII"] gives the same as "string". $\endgroup$
    – funnyp0ny
    Commented Oct 31, 2014 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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