ZString
Standard data type: 8 bit character string
Syntax
`
Dim variable As ZString * size
Dim variable As ZString Ptr
`
Description
A `ZString` is a C-style fixed-size array of chars. It has no descriptor so it's faster to pass it as an argument to functions. FreeBASIC avoids any overflow that could occur, by truncating the contents.
A `ZString` Ptr can point to a standard `ZString`, also can be used to implement an "user-managed" `ZString`, in this case `Allocate`/`Reallocate`/`Deallocate` must be used to size-resize-dispose it and is up to the user to avoid overflows .
The end of the string is marked by a character 0 ASCII, this is automatically managed by the FreeBASIC string handling functions. A character 0 ASCII must never enter in the text of a `ZString` or it will be truncated, as no descriptor exists .
In a `ZString`, `Len` returns the size of the contained string and `SizeOf` returns the space allocated to the `ZString`.
This type is provided for easy interfacing with C libraries and to also replace the fixed-length strings, that can't be managed through pointers. Any intrinsic string functions like `Left` will work with `ZString`'s too, plus any string operator.
Example
`
Dim As ZString * 14 str1 => "hello, world"
Print str1
Print Len(str1) 'returns 12, the size of the string it contains
Print SizeOf(str1) 'returns 14, the size of the variable
`
`
Dim As ZString Ptr str2
str2 = Allocate( 14 )
*str2 = "hello, world"
Print *str2
Print Len(*str2) 'returns 12, the size of the string it contains
Print SizeOf(*str2) 'returns len(zstring), the size of the variable
`
Dialect Differences

- Not available in the -lang qb dialect unless referenced with the alias `__Zstring`.

Differences from QB

- New to FreeBASIC

See also

- `String`
- `WString`