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 Shared Function Replace ( _
    Expression As String, _
    Find As String, _
    Replacement As String, _
    Start As Integer, _
    Count As Integer, _
    Compare As CompareMethod _
) As String
public static string Replace(
    string Expression,
    string Find,
    string Replacement,
    int Start,
    int Count,
    CompareMethod Compare


  • Expression
    Type: System.String
    Required. String expression containing substring to replace.
  • Find
    Type: System.String
    Required. Substring being searched for.
  • Replacement
    Type: System.String
    Required. Replacement substring.
  • Start
    Type: System.Int32
    Optional. Position within Expression where substring search is to begin. If omitted, 1 is assumed.
  • Count
    Type: System.Int32
    Optional. Number of substring substitutions to perform. If omitted, the default value is –1, which means "make all possible substitutions."

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")

Version Information


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.