MaskedTextProvider.Replace Method (String, Int32)

Replaces a range of editable characters starting at the specified position with the specified string.

Namespace: System.ComponentModel
Assembly: System (in system.dll)

public bool Replace (
	string input,
	int position
public boolean Replace (
	String input, 
	int position
public function Replace (
	input : String, 
	position : int
) : boolean
Not applicable.



The String value used to replace the existing editable characters.


The zero-based position to search for the first editable character to replace.

Return Value

true if all the characters were successfully replaced; otherwise, false.

Exception typeCondition


The input parameter is a null reference (Nothing in Visual Basic).

The Replace(String,Int32) method searches for the first editable position at or beyond the specified position, pos. Operating under the assumption that there are enough editable positions after this point, the existing character values are replaced one-by-one with the contents of the replacement string parameter, input.

The following conditions are considered errors. When an error occurs, no replacement occurs and Replace(String,Int32) returns false.

  • The pos parameter is less than zero or greater than the Length of the formatted string.

  • There are not enough editable positions in the formatted string to hold the contents of the replacement string.

  • One of the replacement character values is not valid because it is not printable or does not match its corresponding mask element.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0