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

Split Function

Syntax

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

Use: Required

Data Type: String

A string to be broken up into multiple strings.

delimiter

Use: Optional

Data Type: String

The character used to delimit the substrings in expression.

count

use: Optional

Data Type: Long

The number of strings to return.

compare

Use: Optional

Data Type: 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 0 of the return array.

  • If delimiteris 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 and 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 Dim sArray( ...

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