Replace Method

Strings.Replace Method

Returns a string in which a specified substring has been replaced with another substring a specified number of times.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static string Replace(
	string Expression,
	string Find,
	string Replacement,
	int Start,
	int Count,
	CompareMethod Compare


Type: System.String
Required. String expression containing substring to replace.
Type: System.String
Required. Substring being searched for.
Type: System.String
Required. Replacement substring.
Type: System.Int32
Optional. Position within Expression where substring search is to begin. If omitted, 1 is assumed.
Type: System.Int32
Optional. Number of substring substitutions to perform. If omitted, the default value is –1, which means "make all possible substitutions."
Type: Microsoft.VisualBasic.CompareMethod
Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings for values.

Return Value

Type: System.String
If Find is zero-length or Nothing, Replace returns copy of Expression. If Replace is zero-length, Replace returns copy of Expression with no occurrences of Find. If Expression is zero-length or Nothing, or Start is greater than length of Expression, Replace returns Nothing. If Count is 0, Replace returns copy of Expression.

The return value of the Replace function is a string that begins at the position specified by Start and concludes at the end of the Expression string, with the substitutions made as specified by the Find and Replace values.

The Compare argument can have the following values.




Performs a binary comparison


Performs a textual comparison

This example demonstrates the Replace function.

Dim TestString As String = "Shopping List"
' Returns "Shipping List".
Dim aString As String = Replace(TestString, "o", "i")


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2016 Microsoft