MathGroup Archive 2008

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

Search the Archive

Re: Variable question

  • To: mathgroup at
  • Subject: [mg92506] Re: Variable question
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at>
  • Date: Thu, 2 Oct 2008 04:34:48 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <gc0tkn$9ci$>

Johney at wrote:

> I have the following test code
> c = 3
> var = "c"
> v = StringTake[var, {1}]
> v
> v is showing up as c but I want it to show up as 3.  Is there a way to do this?

What you are looking for is the built-in function *ToExpression*, which 
takes a string of characters as argument, transforms it into a regular 
Mathematica expression that is evaluated, then the result of the 
evaluation is returned.

   In[1]:= c = 3
           var = "c"
           v = ToExpression[var]

   Out[1]= 3

   Out[2]= "c"

   Out[3]= 3

   Out[4]= 3

-- Jean-Marc

  • Prev by Date: Re: command line options: -initfile vs -run
  • Next by Date: Re: Variable question
  • Previous by thread: Re: Variable question
  • Next by thread: Re: Variable question