Name

Split Function

Syntax

Split(expression, [delimiter[, count[, compare]]])
expression

Use: Required

Data Subtype: String

A string to be broken up into multiple strings.

delimiter

Use: Optional

Data Subtype: String

The character used to delimit the substrings in expression.

count

use: Optional

Data Subtype: Long

The number of strings to return.

compare

Use: Optional

Data Subtype: Long

The method of comparison. Possible values are vbBinaryCompare or vbTextCompare. Note that both are intrinsic VBScript constants; you do not have to define them yourself using the Const statement.

Return Value

A variant array consisting of the arguments passed into the function.

Description

Parses a single string containing delimited values into an array.

Rules at a Glance

  • If delimiter isn’t found in expression, Split returns the entire string in element of the return array.

  • If delimiter is omitted, a space character is used as the delimiter.

  • If count is omitted or its value is -1, all strings are returned.

  • The default comparison method is vbBinaryCompare. If delimiter is an alphabetic character, this setting controls whether the search for it in expression is case-sensitive (vbBinaryCompare) or not (vbTextCompare).

  • Once count has been reached, the remainder of the string is placed, unprocessed, into the next element of the returned array.

Programming Tips & Gotchas

  • The variable you declare to assign the return value of Filter must be a simple variant, rather than a variant array. The following code is incorrect:

    ' Incorrect ...

Get VBScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.