FBWiki : KeyPgString

FBWiki :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

STRING


Standard data type: 8 bit character string

Syntax:
dim variable as String [ * size]

Description:
A String is an array of characters.

A String declared without the size parameter is dynamically resized depending on the length of the string. The length can range from 0 bytes to 2 gigabytes. A descriptor contains a pointer to the actual string and the length of the string. Varptr will return a pointer to the descriptor, while Strptr will point to the actual string.
Despite the use of the descriptor, an implicit NULL character (chr(0)) is added to the end of the string, to allow passing them to functions in external libraries without making slow copies. FreeBASIC's internal functions will ignore this character, and not treat it as part of the string.

A String declared with size is a QB-style fixed length string. It has no descriptor and it is not resized to fit its contents. As in QB, if data overflows the size of the string, it is truncated on the right side.
Fixed length strings are also terminated with a NULL character, and so they use size + 1 bytes of space. This NULL terminator may be removed in future, to prevent the redundant character complicating data layout in user-defined Types.

String variable names need not end in a dollar sign $ as in other dialects of BASIC. In lang fb variable suffixes, including the dollar sign, are disallowed entirely.

Note: When passing Strings as parameters to Subs, they should always be passed by reference (ByRef). Currently, ByVal does not pass a copy of the string, but a Pointer to the string data. This can cause unexpected behavior.

Examples:
'' Compile with -lang fblite or qb

#lang "fblite"

'' Variable-length
Dim a As String
a = "Hello"

'' Or
Dim b$
b$ = "World"

'' Fixed-length
Dim c As String * 32
c = "Hello World"


Differences from QB:

See also:

Back to Standard Data Types
Back to String Functions

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.0



sf.net phatcode