StringPolyfillExtensionReplace Method

Returns a new String in which all occurrences of a specified String in the current String are replaced with another specified String, using the provided comparison type.

Definition

Namespace: FolkerKinzel.Strings
Assembly: FolkerKinzel.Strings (in FolkerKinzel.Strings.dll) Version: 9.4.0+10a7d4d71aa960998e32ac0ac6c4fcbe4164c917
C#
public static string Replace(
	this string s,
	string oldValue,
	string? newValue,
	StringComparison comparisonType
)

Parameters

s  String
The source String.
oldValue  String
The string to replace.
newValue  String
The String to replace all occurrences of oldValue.
comparisonType  StringComparison
An enumeration value that specifies the rules for the comparison.

Return Value

String
A String that is equivalent to s except that all instances of oldValue are replaced with newValue. If oldValue is not found in s, the method returns s unchanged.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type String. 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).

Exceptions

NullReferenceExceptions is null.
ArgumentNullExceptionoldValue is null.
ArgumentException

oldValue is Empty

- or -

comparisonType is not a defined value of the StringComparison enumeration.

See Also