Re: Problems with Read[stream,String] after Read[stream,Number]
- To: mathgroup at smc.vnet.net
- Subject: [mg13791] Re: [mg13776] Problems with Read[stream,String] after Read[stream,Number]
- From: David Withoff <withoff>
- Date: Fri, 28 Aug 1998 04:18:16 -0400
- Sender: owner-wri-mathgroup at wolfram.com
> I have noticed what seems an inconsistency in the way Mathematica
> imports data from a file. The strange (to me, at least) behavior
> appears when one attempts to read a line with String data immediately
> after reading a line with Number data.
> In:= !!test.dat
> In:= strm=OpenRead["test.dat"];
> In:= Read[strm,String] (*Read Line 1 as String *) Out= 1
> In:= Read[strm,Number] (*Read Line 2 as Number *) Out= 2
> In:= Read[strm,String] (* Attempt to read Line 3 as String *)
> In:= Read[strm,String] (* Second attempt to read Line 3 as String *)
> Out= 3
> In:= Read[strm,Number] (* Read Line 4 as Number *) Out= 4 In:=
> What am I missing here?
> Thanks for any explanations or pointers thereto.
String format reads everything up to the next newline character and
leaves the stream pointer after the newline character.
Number format reads the next number and leaves the stream pointer after
This means that, after reading Number format from a number followed by a
newline character, the stream pointer will be left before the newline
character. Reading String format when the stream pointer occurs
immediately before a newline character returns an empty string.
Skip[strm, String] is often used in situations like this where the
purpose is to flush any remaining characters on a line and start with a
Prev by Date:
Re: Disappearing variables
Next by Date:
Previous by thread:
Problems with Read[stream,String] after Read[stream,Number]
Next by thread:
Re: Matrix Multiplication