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

String Function

Syntax

String(number, character)
number

Use: Required

Data Type: Long

The length of the required string.

character

Use: Required

Data Type: Variant

Character or character code used to create the required string.

Return Value

A string made up of character, repeated number times.

Description

Creates a string comprising a specified single character repeated a specified number of times.

Rules at a Glance

  • If number contains Null, Null is returned.

  • If character contains Null, Null is returned.

  • character can be specified as a string or as an ANSI character code. For example:

    strBuffer1 = String(128, "=")     ' Fill with "="
    strBuffer2 = String(128, 0)       ' Fill with Chr$(0)
  • If character consists of multiple characters, the first character is used only, and the remainders are discarded.

Programming Tips and Gotchas

  • The String function is useful for creating long strings of _, -, or = characters to create horizontal lines for delimiting sections of a report.

VB/VBA Differences

VBScript does not support the VBA String$ function.

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