コード例 #1
0
        /// <summary>
        /// Replaces all occurrences of the previously defined pattern with the
        /// <paramref name="replacement"/> pattern, starting at the character position
        /// <paramref name="startat"/>.
        /// </summary>
        public string Replace(string input, string replacement, int count, int startat, ref long replacements)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (replacement == null)
            {
                throw new ArgumentNullException(nameof(replacement));
            }

            // a little code to grab a cached parsed replacement object
            RegexReplacement repl = (RegexReplacement)_replref.Get();

            if (repl == null || !repl.Pattern.Equals(replacement))
            {
                repl = RegexParser.ParseReplacement(replacement, caps, capsize, capnames, roptions);
                _replref.Cache(repl);
            }

            return(repl.Replace(this, input, count, startat, ref replacements));
        }