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.