Syntax
|
String
|
Description
|
A data type capable of holding a number of characters.
|
Comments
|
Strings are used to hold sequences of characters, each character having a value between 0 and 255. Strings can be any length up to a maximum length of 32767 characters.
Strings can contain embedded nulls, as shown in the following example:
s$ = "Hello" + Chr$(0) + "there" 'String with embedded null
|
|
The length of a string can be determined using the
Len
function. This function returns the number of characters that have been stored in the string, including unprintable characters.
The type-declaration character for String is
$
.
|
|
String variables that have not yet been assigned are set to zero-length by default.
|
|
Strings are normally declared as variable-length, meaning that the memory required for storage of the string depends on the size of its content. The following script statements declare a variable-length string and assign it a value of length 5:
Dim s As String
s = "Hello" 'String has length 5.
|
|
Fixed-length strings are given a length in their declaration:
Dim s As String * 20
s = "Hello" 'String has length 20 (internally pads with spaces).
|
|
When a string expression is assigned to a fixed-length string, the following rules apply:
|
|
- If the string expression is less than the length of the fixed-length string, then the fixed-length string is padded with spaces up to its declared length.
|
|
- If the string expression is greater than the length of the fixed-length string, then the string expression is truncated to the length of the fixed-length string.
Fixed-length strings are useful within structures when a fixed size is required, such as when passing structures to external routines.
|
|
The storage for a fixed-length string depends on where the string is declared, as described in the following table:
|
|
Strings Declared
|
Are Stored
|
|
In structures
|
In the same data area as that of the structure. Local structures are on the stack; public structures are stored in the public data space; and private structures are stored in the private data space. Local structures should be used sparingly as stack space is limited.
|
|
In arrays
|
In the global string space along with all the other array elements.
|
|
Local routines
|
On the stack. The stack is limited in size, so local fixed-length strings should be used sparingly.
|
See Also
|
Currency (data type);Date (data type); Double (data type); Integer (data type); Long (data type); Object (data type); Single (data type); Variant (data type); Boolean (data type); DefType (statement); CStr (function).
|