Date: Oct 10, 2013 6:23 PM
Author: Derek Goring
Subject: Re: input string used as function input
On Friday, October 11, 2013 10:28:05 AM UTC+13, Jason wrote:
> I would like to take an input string and convert it to a function name.
> For example I have the arrays A=[1,2],B=[2,3],C=[4,5]. I then get user input "A,B". I want to take that string and convert it to reference to the arrays A and B to put into a function that requires 2 arrays as input myFun(array1,array2). That way i can also get input "B,C" and pass in B and C into my function.
The best way is to use a structure which has fields s.A, s.B, and s.C
Then you can get the fields as strings and refer to them like this:
where string1 and string2 are 'A','B', or 'C'
If someone tries to tell you that that the evil function eval is the way to go, ignore them. Use of eval inevitably results in grief.