MathGroup Archive 2004

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

Search the Archive

RE: removing letters from alphanumeric data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48401] RE: [mg48377] removing letters from alphanumeric data
  • From: David.Annetts at csiro.au
  • Date: Fri, 28 May 2004 00:50:29 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Charles

> I am able to find and read in from a data header a particular variable
> value, my difficulty is in my attempt to drop the letters that follow
> the number I need to retrieve.
> 
> For example, I'll use Find to locate the position of the variable
> "Temperature" and then store the value that follows it, however there
> is generally a "C" or something after the temperature value, e.g.
> "45C".  All I need is the value 45.

1.	Import your data as strings 
2.	Apply StringReplace[]; to get rid of the offending character(s)
3.	Read numbers from your "edited" strings.

For example, after generating some test data & dumping it to file via
	test = StringJoin[ToString[#], "C"] & /@ Range[-10, 10];
	Export["test.txt", test, "List"];

We can try
	str = Import["test.txt", "List"]
	str = StringReplace[#, {"C" -> ""}] & /@ str
	num = Read[StringToStream[#], Number] & /@ str
	Head[#] & /@ {First@str, First@num}

Statement is not necessary, it just shows we've converted the strings to
numbers, even though in the front end, they look the same.

> Also, If there is no entry at all is there a way to put a placeholder
> value in it place, instead a Null.

If I understand properly, just replace "Null" with your desired
placeholder.  Following on from the above example, 
	newt = Join[str, {Null}, str]
	repl = newt /. Null -> "*"

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: Manipulating notebooks. Request for examples
  • Next by Date: [newbie] from right to left
  • Previous by thread: Re: removing letters from alphanumeric data
  • Next by thread: [Fwd: Re: Mathematica Trial]--> CalculationCenter 2