Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

RE: Using ReadList to read a string

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83827] RE: [mg83781] Using ReadList to read a string
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Sun, 2 Dec 2007 04:00:25 -0500 (EST)
  • References: <200711301023.FAA06237@smc.vnet.net>

Hi Donald,

> Or is there some other function I should be using other than 
> Import and/or ReadList?
> 
> Thank you in advance for any help you can give me.  

My suggestion is to read the entire file as a String, then post-process.

inpu = OpenRead["d:/Tmpfiles/DuBois.txt"]
idata = ReadList[inpu, String];
Close[inpu];

idata = StringReplace[idata, {"\"" -> ""}];

pdata = Read[
    StringToStream[#], {Number, {Word, Word, Word, Word}, Word, 
     Number, Number, Number, Number, Number}] & /@ idata

fdata  = Flatten@{#[[1]], addSpace[#[[2]]], Rest@Rest[#]} & /@ pdata

addSpace[str_List] := Module[
  {tmp},
  tmp = StringJoin[#, " "] & /@ str;
  StringJoin[tmp]
  ]

Regards,

Dave.



  • Prev by Date: combine red green and blue channels
  • Next by Date: Re: Using ReadList to read a string
  • Previous by thread: Re: Using ReadList to read a string
  • Next by thread: Re: Using ReadList to read a string