Help Center

DWSTRING.Constructorsconstructor

Initialize the class with the specified value.

String ManagementconstructorDWSTRING.incdoc-orphan
No implementation located. This member is documented, but the source scan found no matching declaration. It is likely declared in a header this scan does not resolve, or provided by a macro.

Syntax

CONSTRUCTOR
CONSTRUCTOR (BYREF wszStr AS CONST WSTRING)
CONSTRUCTOR (BYVAL pwszStr AS WSTRING PTR)
CONSTRUCTOR (BYREF ansiStr AS STRING, BYVAL nCodePage AS UINT = 0)
CONSTRUCTOR (BYREF dws AS DWSTRING)
CONSTRUCTOR (BYREF bs AS BSTRING)
CONSTRUCTOR (BYVAL nChars AS LONG, BYREF wszFill AS CONST WSTRING)
CONSTRUCTOR (BYVAL n AS LONGINT)
CONSTRUCTOR (BYVAL n AS DOUBLE)

Description

  1. Creates an empty Unicode string buffer with an initial null-terminated string.
  2. Initializes a DWSTRING instance from a wide string pointer.
  3. Initializes a DWSTRING from an ANSI or UTF-8 encoded string, with optional code page support. For a list of code pages see: Code Page Identifiers.aspx)
  1. Creates a copy of an existing DWSTRING.
  2. Creates a DWSTRING with a fixed-length buffer, initialized with a fill character.
  3. Initializes a DWSTRING with a numeric value, allowing automatic conversion.

Remarks

DWSTRING works transparently with literals and Free Basic native strings, e.g. It can be used with Windows API functions, e.g. We can use arrays of DWSTRING strings transparently, e.g. A two-dimensional array

REDIM PRESERVE / ERASE You can also use it with files:

Using FreeBasic intrinsic statements: Using the Windows API:

Notice that, contrarily to CreateFileW, FreeBasic's OPEN statement doesn't allow to use unicode for the file name.

Examples

Example: DIM dws AS DWSTRING

DIM wsz AS WSTRING * 30 = "This is a test string" DIM dwsText AS DWSTRING = wsz

Example: DIM s AS STRING = "Hello, world"

DIM dws AS DWSTRING = s

Example: DIM dws AS DWSTRING = DWSTRING("Hello, utf", CP_UTF8)

Example: DIM dws1 AS DWSTRING = "Test string"

DIM dws2 AS DWSTRING = dws1

Example: DIM dws AS DWSTRING = DWSTRING(260, " ")

Example: DIM dwsNum AS DWSTRING = 12345 Example: DIM dwsFloat AS DWSTRING = 3.1415

DIM dws AS DWSTRING = "One" DIM s AS STRING = "Three" dws = dws & " Two " & s PRINT dws

DIM nLen AS LONG = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0) DIM dwsText AS DWSTRING = WSPACE(nLen + 1) SendMessageW(hwnd, WM_GETTEXT, nLen + 1, cast(LPARAM, *cwsText)) dwsText = LEFT(dwsText, LEN(dwsText) - 1) PRINT dwsText

DIM rg(1 TO 10) AS DWSTRING FOR i AS LONG = 1 TO 10 rg(i) = "string " & i NEXT FOR i AS LONG = 1 TO 10 PRINT rg(i) NEXT

DIM rg2 (1 TO 2, 1 TO 2) AS DWSTRING rg2(1, 1) = "string 1 1" rg2(1, 2) = "string 1 2" rg2(2, 1) = "string 2 1" rg2(2, 2) = "string 2 2" PRINT rg2(2, 1)

REDIM rg(0) AS DWSTRING rg(0) = "string 0" REDIM PRESERVE rg(0 TO 2) AS DWSTRING rg(1) = "string 1" rg(2) = "string 2" PRINT rg(0) PRINT rg(1) PRINT rg(2) ERASE rg

DIM dws AS DWSTRING = "Дмитрий Дмитриевич Шостакович" DIM f AS LONG = FREEFILE OPEN "Test.txt" FOR OUTPUT ENCODING "utf16" AS #f PRINT #f, dws CLOSE #f

' // Writing to a file DIM dwsFilename AS DWSTRING = "тест.txt" DIM dwsText AS DWSTRING = "Дмитрий Дмитриевич Шостакович" DIM hFile AS HANDLE = CreateFileW(dwsFilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) IF hFile THEN DIM dwBytesWritten AS DWORD DIM bSuccess AS LONG = WriteFile(hFile, dwsText, LEN(dwsText) * 2, @dwBytesWritten, NULL) CloseHandle(hFile) END IF

' // Read the file hFile = CreateFileW(dwsFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL) IF hFile THEN DIM dwFileSize AS DWORD = GetFileSize(hFile, NULL) IF dwFileSize THEN

DIM dwsOut AS DWSTRING = WSPACE(dwFileSize \ 2)
  DIM bSuccess AS LONG = ReadFile(hFile, *dwsOut, dwFileSize, NULL, NULL)
  CloseHandle(hFile)
  PRINT dwsOut

END IF END IF

Reference

  • Include file DWSTRING.inc
  • Documented in String Management/DWSTRING Class.md
  • Topic: DWSTRING Class