StringBuilderExtensionReplace(StringBuilder, Char, Char, Int32) Method

Replaces, within a substring of builder, all occurrences of a specified character with another specified character.

Definition

Namespace: FolkerKinzel.Strings
Assembly: FolkerKinzel.Strings (in FolkerKinzel.Strings.dll) Version: 9.4.0+10a7d4d71aa960998e32ac0ac6c4fcbe4164c917
C#
public static StringBuilder Replace(
	this StringBuilder builder,
	char oldChar,
	char newChar,
	int startIndex
)

Parameters

builder  StringBuilder
The StringBuilder whose content is changed.
oldChar  Char
The character to replace.
newChar  Char
The character that replaces oldChar.
startIndex  Int32
The position in builder where the substring begins.

Return Value

StringBuilder
A reference to builder with oldChar replaced by newChar 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 oldChar in the current instance. The size of builder is unchanged after the replacement.

Exceptions

ArgumentNullExceptionbuilder is null.
ArgumentOutOfRangeException

startIndex is less than zero.

- or -

startIndex indicates a character position not within builder.

See Also