Export (0) Print
Expand All

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)

'Declaration
Public Shared Function Replace ( _
	Expression As String, _
	Find As String, _
	Replacement As String, _
	Start As Integer, _
	Count As Integer, _
	Compare As CompareMethod _
) As String

Parameters

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."
Compare
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.

Constant

Description

Binary

Performs a binary comparison

Text

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

Silverlight

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

ADD
Show:
© 2014 Microsoft