Name
String Function
Syntax
String(number,character)
-
number Use: Required
Data Subtype: Long
The length of the required string.
-
character Use: Required
Data Subtype: Variant
Character or character code used to create the required string.
Return Value
A Variant of subtype 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
numbercontainsNull,Nullis returned.If
charactercontainsNull,Nullis returned.charactercan 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
characterconsists of multiple characters, only the first character is used, and the remainder are discarded.
Programming Tips & Gotchas
The
Stringfunction 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, which returns a string rather than aVariant of Subtype
string.
See Also
| Space Function |
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.
Read now
Unlock full access