Re: Re: How to convert string to variable name
- To: mathgroup at smc.vnet.net
- Subject: [mg39886] Re: [mg39866] Re: How to convert string to variable name
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sun, 9 Mar 2003 18:39:24 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
It does work, but you need to evaluate the left hand side: Evaluate[Symbol["x"]]=13; In[14]:= x Out[14]= 13 Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ On Sunday, March 9, 2003, at 07:28 pm, Bob Harris wrote: > I wrote: >>> ... for a given string, how can I assign to the variable whose name >>> is >>> defined by that string? > > and Hermann Schmitt replied: >> I would do it the following way: >> ToExpression["z = ....."]; > > Thanks, that appears to be what I want. I just have to build a string > that > contains the entire assignment. > > A couple people suggested using Symbol[], but I don't see how that > would > work. For example, > > Symbol["x"] = 13 > > doesn't create a symbol x with value 13. Instead, it simply produces > an > error message informing me that "Tag Symbol in Symbol["x"] is > Protected." > > Thanks, > Bob H > > > >