Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I spent a reasonable amount of time to find the origin of an error in a larger code segment.

str = StringToStream["a1;b1;c1"];

data1 = ReadList[str, Record, 1];
StringLength[data1]
{8}

SetStreamPosition[str, 0];

data2 = Read[str, Record];
StringLength[data2]
8

Close[str];

You can't calculate with a {8}.

share|improve this question

2 Answers 2

Because

data1 == {"a1;b1;c1"} 

and

data2 == "a1;b1;c1"

Edit

Note that StringLength has the attribute Listable, so it will map across the items in a list.

share|improve this answer

data1 is {"a1;b1;c1"} and data2 is "a1;b1;c1".

And StringLength[{"abc", "defg", "hijkl"}] is {3,4,5}

It's all because ReadList unsurprisingly returns a list

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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