0
$\begingroup$

How can I assign a value for a symbol composed of a string plus and another string converted from integer?

n=3;
Symbol["as"<>ToString[n]]=4;

So I want to assign a value 4 to the new symbol as3. But it does not work.

$\endgroup$
2
  • $\begingroup$ Evaluate@Symbol["as" <> ToString[n]] = 4. It will only work once. $\endgroup$
    – march
    Oct 11, 2017 at 21:33
  • $\begingroup$ Linked topic should answer your question, let me know if you disagree with closing. $\endgroup$
    – Kuba
    Oct 11, 2017 at 21:36

1 Answer 1

1
$\begingroup$

Is this what you want?

n = 3;
Set[#, 4]& @ Symbol["as" <> ToString[n]]
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.