O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Replace Function

Syntax

Replace(string, stringToReplace, replacementString [, start[, count[, 
compare]]])
string

Use: Required

Data Type: String

The complete string containing the substring to be replaced.

stringToReplace

Use: Required

Data Type: String

The substring to be found by the function.

replacementString

Use: Required

Data Type: String

The new substring to replace stringToReplace in string.

start

Use: Optional

Data Type: Long

The character position in string at which the search for stringToReplace begins.

count

Use: Optional

Data Type: Long

The number of instances of stringToReplace to replace.

compare

Use: Optional

Data Type: Integer

The method that compares stringToReplace with string ; its value can be vbBinaryCompare or vbTextCompare.

Return Value

The return value from Replace depends on the parameters you specify in the argument list, as the following table shows:

If

Return value

string = ""

Zero-length string (“”)

string is Null

An error

StringToReplace = ""

Copy of string

replacementString = ""

Copy of string with all instances of stringToReplace removed

start > Len(string)

Zero-length string (“”)

count = 0

Copy of string

Description

Replaces a given number of instances of a specified substring in another string.

Rules at a Glance

  • If start is omitted, the search begins at the start of the string.

  • If count is omitted, its value defaults to -1, which means that all instances of the substring after start are replaced.

  • vbBinaryCompare is case-sensitive; that is, Replace matches both character and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required