Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

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
)

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 that starts a substring used for replacement. The return value of Replace is a string that begins at Start, with appropriate substitutions. 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
Replace returns the following values.

If

Replace returns

Find is zero-length or Nothing

Copy of Expression

Replace is zero-length

Copy of Expression with no occurrences of Find

Expression is zero-length or Nothing, or Start is greater than length of Expression

Nothing

Count is 0

Copy of Expression

ExceptionCondition
ArgumentException

Count < -1 or Start <= 0.

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

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.