Skip to Content
VB & VBA in a Nutshell: The Language
book

VB & VBA in a Nutshell: The Language

by Paul Lomax
October 1998
Intermediate to advanced
656 pages
16h 10m
English
O'Reilly Media, Inc.
Content preview from VB & VBA in a Nutshell: The Language
Replace Function (VB6)

Named Arguments

No

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: VbCompareMethod constant

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

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, all instances of the substring after start are replaced.

  • vbBinaryCompare ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Absolute Beginner's Guide to VBA

Absolute Beginner's Guide to VBA

Paul McFedries
Visual Basic 2015 Unleashed

Visual Basic 2015 Unleashed

Alessandro Del Sole

Publisher Resources

ISBN: 1565923588Catalog PageErrata