MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Unformatted File IO


Yas

The code splits "hello there" which must stay intact as a list element.  Any
ideas?  Thanks.

Bruce

----- Original Message ----- 
From: "Yasvir tesiram" <yat at omrf.ouhsc.edu>
To: mathgroup at smc.vnet.net
>
> The contents of test.txt are as you state below.
> SetDirectory["pathTotest"];
> /*check to see that the file is there*/
> FileNames[]
>
> (*open a file handle to the file (handle), read in the contents line by
> line (RecordSeparator) as words separated by any of the possible
> separators (WordSeparators) *)
>
> (*note the "\"" in the list of WordSeprators is intentional because of
> your double quoted strings*)
>
> handle = OpenRead["test.txt"];
> z = ToExpression[
>      ReadList[handle, Word, RecordSeparators -> {"\n"},
>        WordSeparators -> {" ", "\t", "\""}, RecordLists -> True]
>      ]
> Close[handle];
>
>
> Yas
>
> Bruce W. Colletti wrote:
>
> > I have an unformatted text file whose records hold reals and
double-quoted
> > strings, all delimited by spaces, e.g.,
> >
> >     "hello there"  2.7
> >     1 2 3 4
> >     9    "abc"      "def"
> >
> > How can I read the file to produce a list of lists, e.g., {{hello there,
2.7},
> > {1,2,3,4}, {9, abc, def}}?



  • Prev by Date: orthonormalized eigenvectors
  • Next by Date: Re: Numerical Optimization of
  • Previous by thread: Re: Unformatted File IO
  • Next by thread: Re: Unformatted File IO