System.Text.StringBuilder.Replace Method

Replaces all occurrences of a specified string in this instance with another specified string.

Syntax

public StringBuilder Replace (string oldValue, string newValue)

Parameters

oldValue
The string to replace.
newValue
The string that replaces oldValue, or null.

Returns

A reference to this instance with all instances of oldValue replaced by newValue.

Exceptions

TypeReason
ArgumentNullException oldValue is a null reference.
ArgumentExceptionThe length of oldvalue is zero.

Remarks

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

Requirements

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0