Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: String to numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg55371] Re: [mg55337] String to numbers
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Sun, 20 Mar 2005 04:12:10 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi John,

> I have data in file in the form of strings, formatted as:
> 
> <2.54   3.11   2.89>
> <3.58   5.24   5.66>
> ... more
> 
> How can I read this into mathematica, and convert the strings 
> to numbers, so I would have
> 
> {{2.54,3.11,2.89},{3.58,5.24,5.66},...{}}

If "erb.txt" is

<2.54   3.11   2.89>
<3.58   5.24   5.66>

Then this file can be read using

inpf = OpenRead["erb.txt"];
idat = ReadList[inpf, Record]
Close[inpf]

pdat = StringReplace[#, {"<"->"", ">"->""}]& /@ idat
fdat = ReadList[StringToStream[#], Number]& /@ pdat 

If you like, replace the first three lines above with Import["Erb.txt",
"Table"];

Regards,

Dave.


  • Prev by Date: Re: filling in an array
  • Next by Date: Re: String to numbers
  • Previous by thread: Re: String to numbers
  • Next by thread: Re: String to numbers