Exemplo n.º 1
0
        /// <summary>
        /// Searches an input string for all occurences of pattern.
        /// </summary>
        /// <param name="input">The string to search in.</param>
        /// <param name="pattern">The string to search for.</param>
        /// <param name="startIndex">The zero-based index to start searching.</param>
        /// <param name="caseSensitive">Whether or not the search should be case sensitive.</param>
        /// <returns>The indices of all occurences of the pattern found, or an empty array if no occurences were found.</returns>
        public static int[] FindAll(string input, string pattern, int startIndex, bool caseSensitive)
        {
            int index = -1;
            int start = startIndex;

            List <int> retval   = new List <int>();
            BoyerMoore searcher = new BoyerMoore(pattern, caseSensitive);

            while ((index = searcher.Search(input, start)) >= 0)
            {
                retval.Add(index);
                start = index + pattern.Length;
            }

            return(retval.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Searches an input string for the first occurence of pattern.
        /// </summary>
        /// <param name="input">The string to search in.</param>
        /// <param name="pattern">The string to search for.</param>
        /// <param name="startIndex">The zero-based index to start searching.</param>
        /// <param name="caseSensitive">Whether or not the search should be case sensitive.</param>
        /// <returns>The index of the pattern if found, or -1 if it is not.</returns>
        public static int Find(string input, string pattern, int startIndex, bool caseSensitive)
        {
            BoyerMoore searcher = new BoyerMoore(pattern, caseSensitive);

            return(searcher.Search(pattern, startIndex));
        }