StringBuilderExtensionReplace(StringBuilder, String, String, Int32) Method

Replaces all occurrences of a specified string in a substring of builder with another specified string.

Definition

Namespace: FolkerKinzel.Strings
Assembly: FolkerKinzel.Strings (in FolkerKinzel.Strings.dll) Version: 9.4.0+10a7d4d71aa960998e32ac0ac6c4fcbe4164c917
C#
public static StringBuilder Replace(
	this StringBuilder builder,
	string oldValue,
	string? newValue,
	int startIndex
)

Parameters

builder  StringBuilder
The StringBuilder whose content is changed.
oldValue  String
The string to replace.
newValue  String
The string that replaces oldValue, or null.
startIndex  Int32
The position in builder where the substring begins.

Return Value

StringBuilder
A reference to builder with all instances of oldValue replaced by newValue in the range from startIndex to the end of builder.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type StringBuilder. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This method performs an ordinal, case-sensitive comparison to identify occurrences of oldValue in the specified substring. If newValue is null or Empty, all occurrences of oldValue are removed.

Exceptions

ArgumentNullExceptionbuilder or oldValue is null.
ArgumentExceptionoldValue is Empty.
ArgumentOutOfRangeException

startIndex is less than zero.

- or -

startIndex indicates a character position not within builder.

- or -

Increasing the capacity of builder would exceed MaxCapacity.

See Also