MathGroup Archive 2002

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

Search the Archive

RE: trying to pull numbers out of a string from a file.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36623] RE: [mg36595] trying to pull numbers out of a string from a file.
  • From: "Annetts, Dave (E&M, North Ryde)" <David.Annetts at csiro.au>
  • Date: Fri, 13 Sep 2002 23:33:33 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Rob,

> inFile = OpenRead["197-tst.txt"]
> y = ReadList[inFile, String, 1, RecordLists -> True]
> Close[inFile];
> 
> This appears to pull in a line. Now I want to take characters 
> 25 to 110 to get just the stuff I want:
> y1=StringTake[y ,{25,110}];
> 
> Here's the output.  StringTake doesn't seem to work.
> 
> StringTake[{aEX-004   2002197 0 0 0 5935.80 5946.66  27.06 
> -1281.9   -229.    321.    317.    367.   -115.    126.    
> 146.   -410.  -426.000000EF   75.}, {25, 110}]
> 
> It doesn't take loading another package as far
> as I can tell from the help.  I'm thinking that it doesn't 
> work because it's trying to work on a list
> rather than a string. I've tried Flatten, and other stuff to 
> try to get to just a string and not a list but
> nothing has worked so far.  I'm a long way from getting to 
> those numbers in there but heck, I
> can't even get to the string.  Can anyone point me in the 
> right direction?

You might try 
lst = Read[StringToStream[y1], {Word, Table[Number, {16}], Word,
Number}]//Flatten;

You can then pick the numbers (or words) from the list "lst".

A quicker alternative might be as follows:-
ifile = ReadList["197-tst.txt", {Word, Table[Number, {16}], Word, Number}];

Regards,

Dave.
==========================================
  Dr. David Annetts
  EM Modelling Analyst
  CSIRO DEM            Tel: +612 9490 5416
  North Ryde           Fax: +612 9490 5467
  Australia         David.Annetts at csiro.au
===========================================


  • Prev by Date: Re: trying to pull numbers out of a string from a file...
  • Next by Date: RE: Arrow pointers rather than Legend
  • Previous by thread: Re: Checking Programming errors; a ?
  • Next by thread: Invert a function