MathGroup Archive 2003

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

Search the Archive

Re: Changing String to Real

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41094] Re: Changing String to Real
  • From: "Lawrence A. Walker Jr." <lwalker701 at earthlink.net>
  • Date: Fri, 2 May 2003 03:58:49 -0400 (EDT)
  • References: <b8lhn5$9e3$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Wuerfel,

StringTake and ToExpression is one method.  The real concern I have for 
this method is that it may not be able to handle numbers fortran 'e' 
notation properly.

I propose another that works for all types of numbers and avoids the 
need to 'count characters'.

It only require that there is some consistent format to the data.

For instance, assuming that a number is always separated from a string 
by ':' then we can use the following construct.

s = StringReplace["Uoc:0.752", ":" -> " "]; (* string should have no 
other spaces *)

str = StringToStream[s];
num = ReadList[str, {Word, Number}][[1]];
Close[str];
num[[1]]

Hope this helps,
Lawrence


Uli Wuerfel wrote:
> Hi there,
> we import a data file and want to extract a number from a string like 
> e.g. Uoc:0.752
> Of course we can extract 0.752 with Stringtake but we need to calculate 
> with this number. How can we make Mathematica to understand it as a real 
> number??
> Thank you for any kind of help,
> Uli
> 
> 




-- 
Lawrence A. Walker Jr.
http://www.kingshonor.com


  • Prev by Date: problems with mathematica plot command
  • Next by Date: Mathematica and JLink
  • Previous by thread: RE: problems with mathematica plot command
  • Next by thread: Re: Changing String to Real