/// <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) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (replacement == null) { throw new ArgumentNullException(nameof(replacement)); } // Gets the weakly cached replacement helper or creates one if there isn't one already. RegexReplacement repl = RegexReplacement.GetOrCreate(_replref, replacement, caps, capsize, capnames, roptions); return(repl.Replace(this, input, count, startat)); }
/// <summary> /// Returns the expansion of the passed replacement pattern. For /// example, if the replacement pattern is ?$1$2?, Result returns the concatenation /// of Group(1).ToString() and Group(2).ToString(). /// </summary> public virtual string Result(string replacement) { if (replacement == null) { throw new ArgumentNullException(nameof(replacement)); } if (_regex == null) { throw new NotSupportedException(SR.NoResultOnFailed); } // Gets the weakly cached replacement helper or creates one if there isn't one already. RegexReplacement repl = RegexReplacement.GetOrCreate(_regex._replref, replacement, _regex.caps, _regex.capsize, _regex.capnames, _regex.roptions); return(repl.Replacement(this)); }
/// <summary> /// Returns the expansion of the passed replacement pattern. For /// example, if the replacement pattern is ?$1$2?, Result returns the concatenation /// of Group(1).ToString() and Group(2).ToString(). /// </summary> public virtual string Result(string replacement) { if (replacement is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.replacement); } Regex?regex = _regex; if (regex is null) { throw new NotSupportedException(SR.NoResultOnFailed); } // Gets the weakly cached replacement helper or creates one if there isn't one already. RegexReplacement repl = RegexReplacement.GetOrCreate(regex.RegexReplacementWeakReference, replacement, regex.caps !, regex.capsize, regex.capnames !, regex.roptions); SegmentStringBuilder segments = SegmentStringBuilder.Create(); repl.ReplacementImpl(ref segments, this); return(segments.ToString()); }
/// <summary> /// Returns the expansion of the passed replacement pattern. For /// example, if the replacement pattern is ?$1$2?, Result returns the concatenation /// of Group(1).ToString() and Group(2).ToString(). /// </summary> public virtual string Result(string replacement) { if (replacement == null) { throw new ArgumentNullException(nameof(replacement)); } if (_regex == null) { throw new NotSupportedException(SR.NoResultOnFailed); } // Gets the weakly cached replacement helper or creates one if there isn't one already. RegexReplacement repl = RegexReplacement.GetOrCreate(_regex._replref, replacement, _regex.caps, _regex.capsize, _regex.capnames, _regex.roptions); Span <char> charInitSpan = stackalloc char[ReplaceBufferSize]; var vsb = new ValueStringBuilder(charInitSpan); repl.ReplacementImpl(ref vsb, this); return(vsb.ToString()); }