The WideString data type is used to hold sequences of International characters, like sentences.
Each character is a WideChar, guaranteed to be 16 bits in size.
WideChar types provide support for multi-byte International character sets such as Chinese, which have vast numbers of characters (idiograms) in their character sets.
Unlike ShortStrings, WideStrings are pointer referenced variables (for Windows - for Linux, they are not). Storage is allocated for an AnsiString only when needed. For example, assigning the value of one AnsiString to another does not allocate storage for a copy of the first string. Instead, the reference count of the first string is incremented, and the second AnsiString set to point to it.
But when the second string is changed, new storage is obtained for this new string, and the reference count for the first string is decremented.
When a string is no longer referenced (the last AnsiString referer is set to nil), it is discarded. This is an example of Delphi managing storage on your behalf.
WideStrings can be assigned from other strings, from functions that return a string, and with concatenations as in the sample code.
When assigning to a 'narrow' string, such as an AnsiString, the double to single byte conversion can have unpredictable results. Use with care.
Converting from AnsiString to WideString is trouble free.
|Strings are indexed with 1 for the first character (arrays start with 0 for the first element).
|Compare two strings for equality
|Change upper case characters in a string to lower case
|Find the position of one string in another
|Change lower case characters in a string to upper case
|Concatenates one or more strings into one string
|Create a copy of part of a string or an array
|Delete a section of characters from a string
|Return the number of elements in an array or string
|Copy bytes of data from a source to a destination
|Pointer to a WideString value
|Changes the size of a string, or the size(s) of an array
|A data type that holds a string of characters
|Variable type holding a single International character
| Download this web site as a Windows program.
|Example code : Assign to two WideStrings and manipulate these
string1, string2 : WideString;
// Assign a famous sentence to the first string
string1 := 'Hello World';
// Assign to the second string
// This simply points string2 at string1
// The 'Hello World' string storage has a reference count of 2
string2 := string1;
// Add to the second string
// This disassociates from string1 - new string storage is
// created to hold the string2 value
string2 := string2 + ', how is everyone?';
// And finally, set the length of the first string to 5
// Display both strings
ShowMessage('String1 = '+string1);
ShowMessage('String2 = '+string2);
|Show full unit code
| String1 = Hello
String2 = Hello World, how is everyone?