This documentation is archived and is not being maintained.

Regex.Replace Method (String, String, Int32, Int32)

.NET Framework 1.1

Replaces up to a specified number of occurrences of a pattern in the input string defined by the regular expression specified in the Regex constructor with a specified replacement string, starting at a specified character position in the input string.

[Visual Basic]
Overloads Public Function Replace( _
   ByVal input As String, _
   ByVal replacement As String, _
   ByVal count As Integer, _
   ByVal startat As Integer _
) As String
public string Replace(
 string input,
 string replacement,
 int count,
 int startat
public: String* Replace(
 String* input,
 String* replacement,
 int count,
 int startat
public function Replace(
   input : String,
 replacement : String,
 count : int,
 startat : int
) : String;


The string to modify.
The replacement string.
Maximum number of times the replacement can occur.
The character position in the input string where the search will begin.

Return Value

The modified character string.


If count is negative, replacements continue to the end of the string. The other two forms of replace simply supply default values for count (-1) and startat (zero when left-to-right, or input.Length when right-to-left).


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Regex Class | Regex Members | System.Text.RegularExpressions Namespace | Regex.Replace Overload List