WString
Standard data type: wide character string
Syntax
`
Dim variable As WString * size
Dim variable As WString Ptr
`
Description
A `WString` is a fixed-size array of wide-chars that never overflows if the size is known at compile-time. It has no descriptor, and does never resize unless it's a pointer and `Allocate`/`Reallocate`/`Deallocate` are used directly.
The end of the string is marked by the character 0, so that character must never be part of a `WString` or the content will be truncated.
This type is provided for support non-Latin based alphabets. Any intrinsic string function like `Left` will work with `WString`s too, as will any string operator.
Besides ASCII files with Unicode escape sequences (\u), FreeBASIC can parse UTF-8, UTF-16LE, UTF-16BE, UTF-32LE and UTF-32BE source files.
The FreeBASIC text file functions can read and write Unicode files in different encodings, provided the `Encoding` is specified when the file is opened. The text is automatically converted to the internal encoding at read and converted back to the file encoding at write.
`SizeOf`( `WString` ) returns the number of bytes used by a `WString` character in the current platform.
Example
`
Dim As WString * 14 str1 => "hello, world"
Print str1
Print Len(str1) 'returns 12, the length of the string it contains
Print SizeOf(str1) 'returns 14 * sizeof(wstring), the number of bytes used by the variable
`
`
Dim As WString Ptr str2
str2 = Allocate( 14 * Len(WString) )
*str2 = "hello, world"
Print *str2
Print Len(*str2) 'returns 12, the length of the string it points to
`
Platform Differences
Support for wstrings relies in the C runtime library available in the platform and the internal format may vary.

- Unicode is not supported in the DOS port of FreeBASIC. In this port a character takes up always 1 byte and `Wstrings` will behave as standard ASCII `Zstrings`
- On Win32 wstrings are encoded in UCS-2 (UTF-16 LE) and a character takes up 2 bytes.
- On Linux wstrings are encoded in UCS-4 and a character takes up 4 bytes.

Dialect Differences

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

Differences from QB

- New to FreeBASIC

See also

- `String` (data type)
- `ZString` (data type)
- `WString` (data type)
- `String` (function)
- `WString` (function)
- `WSpace`
- `WStr`
- `WChr`
- `WBin`
- `WHex`
- `WOct`
- `Winput()`