Beispiel #1
0
        /// <summary>
        /// locate one text string within a second text string,
        /// and return the number of the starting position of the first
        /// text string from the first character of the second text string.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 2 - 3 items: find_text, within_text, [start_num].
        /// </para>
        /// <para>
        /// Find_text is the text you want to find.
        /// </para>
        /// <para>
        /// Within_text is the text in which you want to search for find_text.
        /// </para>
        /// <para>
        /// [Start_num] is the character number in within_text at which you want to
        /// start searching, the default value is 1.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            string s          = CalcConvert.ToString(args[0]);
            string str2       = CalcConvert.ToString(args[1]);
            int    startIndex = CalcHelper.ArgumentExists(args, 2) ? CalcConvert.ToInt(args[2]) : 1;

            startIndex--;
            if (startIndex < 0)
            {
                return(CalcErrors.Value);
            }
            int index = -1;

            try
            {
                if ((s.IndexOf('*') == -1) && (s.IndexOf('?') == -1))
                {
                    index = str2.ToLower().IndexOf(s.ToLower(), startIndex);
                }
                else
                {
                    Match match = new Regex(LookupHelper.CreateStringcomparisonRegexPattern(s).ToLower()).Match(str2.ToLower(), startIndex);
                    if ((match != null) && match.Success)
                    {
                        index = match.Index;
                    }
                }
            }
            catch
            {
            }
            if (index == -1)
            {
                return(CalcErrors.Value);
            }
            return((int)(index + 1));
        }