Exemple #1
0
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0,
                                           ValueEval arg1)
        {
            String arg;
            int    index;

            try
            {
                arg   = TextFunction.EvaluateStringArg(arg0, srcRowIndex, srcColumnIndex);
                index = TextFunction.EvaluateIntArg(arg1, srcRowIndex, srcColumnIndex);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }

            if (index < 0)
            {
                return(ErrorEval.VALUE_INVALID);
            }

            String result;

            if (_isLeft)
            {
                result = arg.Substring(0, Math.Min(arg.Length, index));
            }
            else
            {
                result = arg.Substring(Math.Max(0, arg.Length - index));
            }
            return(new StringEval(result));
        }
Exemple #2
0
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0)
        {
            int arg;

            try
            {
                arg = TextFunction.EvaluateIntArg(arg0, srcRowIndex, srcColumnIndex);
                if (arg < 0 || arg >= 256)
                {
                    throw new EvaluationException(ErrorEval.VALUE_INVALID);
                }
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            return(new StringEval(Convert.ToString((char)arg, CultureInfo.CurrentCulture)));
        }
Exemple #3
0
 public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1,
                                    ValueEval arg2)
 {
     try
     {
         String needle   = TextFunction.EvaluateStringArg(arg0, srcRowIndex, srcColumnIndex);
         String haystack = TextFunction.EvaluateStringArg(arg1, srcRowIndex, srcColumnIndex);
         // evaluate third arg and convert from 1-based to 0-based index
         int startpos = TextFunction.EvaluateIntArg(arg2, srcRowIndex, srcColumnIndex) - 1;
         if (startpos < 0)
         {
             return(ErrorEval.VALUE_INVALID);
         }
         return(Eval(haystack, needle, startpos));
     }
     catch (EvaluationException e)
     {
         return(e.GetErrorEval());
     }
 }