Functions Delphi

function WideCharToString ( Source : PWideChar; ) : string;


Description
The WideCharToString function converts a null terminated WideChar string or array to a normal string.

WideChar's are 2 bytes in size, to accomodate International character sets, such as Chinese, where the number of characters exceeds 256.

Such a double byte to single byte conversion will preserve the double byte size when it cannot be mapped to a single byte. So a 10 character WideChar string will yield anything from 10 to 20 characters in the resulting string.

Related commands
StringToWideChar Converts a normal string into a WideChar 0 terminated buffer

Example code : A simple example
var
wideCharArray : array[0..5] of WideChar;
myString : String;
begin
// Set up our WideChar array
wideCharArray[0] := 'H';
wideCharArray[1] := 'e';
wideCharArray[2] := 'l';
wideCharArray[3] := 'l';
wideCharArray[4] := 'o';
wideCharArray[5] := #0; // Terminates WideChar strings
// Copy to a normal string
myString := WideCharToString(wideCharArray);
// Show what the copy gave
ShowMessage(myString);
end;

Show full unit code
Hello