Click or drag to resize
StringBuilderReplace Method (String, String, Int32, Int32)
Replaces, within a substring of this instance, all occurrences of a specified string with another specified string.

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax
C#
public StringBuilder Replace(
	string oldValue,
	string newValue,
	int startIndex,
	int count
)

Parameters

oldValue
Type: SystemString
The string to replace.
newValue
Type: SystemString
The string that replaces oldValue, or null.
startIndex
Type: SystemInt32
The position in this instance where the substring begins.
count
Type: SystemInt32
The length of the substring.

Return Value

Type: StringBuilder
A reference to this instance with all instances of oldValue replaced by newValue in the range from startIndex to startIndex + count - 1.
Exceptions
ExceptionCondition
ArgumentNullExceptionoldValue is null.
ArgumentExceptionThe length of oldValue is zero.
ArgumentOutOfRangeExceptionstartIndex or count is less than zero.-or- startIndex plus count indicates a character position not within this instance.-or- Enlarging the value of this instance would exceed MaxCapacity.
See Also