Share via


Replace Method (String, String)

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

In a specified input string, replaces all strings that match a regular expression pattern with a specified replacement string.

Namespace:  System.Text.RegularExpressions
Assembly:  System.Text.RegularExpressions (in System.Text.RegularExpressions.dll)

Syntax

'Declaration
Public Function Replace ( _
    substituteIn As String, _
    substitution As String _
) As String
public string Replace(
    string substituteIn,
    string substitution
)
public:
String^ Replace(
    String^ substituteIn, 
    String^ substitution
)
member Replace : 
        substituteIn:string * 
        substitution:string -> string 
public function Replace(
    substituteIn : String, 
    substitution : String
) : String

Parameters

Return Value

Type: System. . :: . .String
A new string that is identical to the input string, except that the replacement string takes the place of each matched string.

Remarks

The search for matches starts at the beginning of the substituteIn string. The regular expression is the pattern defined by the constructor for the current Regex object.

The substitution parameter specifies the string that is to replace each match in substituteIn. substitution can consist of any combination of literal text and substitutions. For example, the replacement pattern a*${test}b inserts the string "a*" followed by the substring that is matched by the test capturing group, if any, followed by the string "b". The * character is not recognized as a metacharacter within a replacement pattern.

.NET Framework Security

See Also

Reference

Regex Class

Replace Overload

System.Text.RegularExpressions Namespace