Ncalc how to evaluate multi-value string parameters

2.1k Views Asked by At

I am using Ncalc to evaluate the presence of some string values

if (@Xval = 'Z','T','F')

this works well when @xval is inputted as a parameter as a single value(@Xval = 'Z'). That will return a true evaluation. I am now looking to evaluate the same formula when @Xval may be say 'Z','H' in other words Xval contains those 2 values and Im trying to find if 'Z' is among them.

The same goes for if (in (@Xval,'Z','H','M'),'T','F') where Im looking for the value of Xval in a group of options (Z,H,M).

Can I do this via custom functions? If so how? Any other ideas?

Thank you

1

There are 1 best solutions below

0
On BEST ANSWER

You can try

   Expression e = new Expression("if (iscontians("ZHM",@Xval),'T','F')", EvaluateOptions.IgnoreCase);
   e.EvaluateFunction += evalFunction;

Write a custom function

private void evalFunction(string name, FunctionArgs args)
        {
            switch (name.ToUpper())
            {

                case "ISCONTAINS":
                    if (args.Parameters.Length < 2)
                        throw new ArgumentException("isContains() takes at least 2 arguments");
                    args.Result = args.Parameters[0].Evaluate().ToString().Contains(args.Parameters[1].Evaluate().ToString());
                    break;
                default:
                    break;
            }
        }