Difference between revisions of "Character and string types"
Jwdietrich (talk | contribs) |
Jwdietrich (talk | contribs) (UnicodeString) |
||
Line 84: | Line 84: | ||
==== Reference ==== | ==== Reference ==== | ||
* [http://www.freepascal.org/docs-html/ref/refsu12.html FPC AnsiString documentation] | * [http://www.freepascal.org/docs-html/ref/refsu12.html FPC AnsiString documentation] | ||
+ | |||
+ | == UnicodeString == | ||
+ | |||
+ | Like '''AnsiStrings''' '''UniCodeStrings''' are reference counted, null-terminated arrays, but they are implemented as arrays of '''WideChars''' instead of regular '''Chars'''. | ||
+ | |||
+ | {| class="wikitable" style="text-align:center; width:390px" | ||
+ | |- | ||
+ | | style="width: 7%;" | || style="width: 7%;" | || style="width: 7%;" | || style="width: 7%;" | || style="width: 7%;" | || style="width: 7%;" | || style="width: 7%;" | || style="width: 7%;" | || style="width: 7%;" | || style="width: 7%;" | a || style="width: 7%;" | || style="width: 7%;" | b || style="width: 7%;" | || style="width: 7%;" | c || style="width: 7%;" | #0 || style="width: 7%;" | #0 | ||
+ | |- | ||
+ | | colspan="4" style="width: 16%;" | RefCount || colspan="4" style="width: 16%;" | Length | ||
+ | |} | ||
+ | |||
+ | ==== Reference ==== | ||
+ | * [http://www.freepascal.org/docs-html/ref/refsu13.html FPC UnicodeString documentation] | ||
[[Category: FPC]] | [[Category: FPC]] | ||
[[Category: RTL]] | [[Category: RTL]] | ||
[[Category: Data types]] | [[Category: Data types]] |
Revision as of 16:50, 28 December 2013
Free Pascal supports several types of characters and strings.
AnsiChar
A variable of type AnsiChar is exactly 1 byte in size, and contains one ASCII character.
a |
Reference
WideChar
A variable of type WideChar is exactly 2 bytes in size, and contains one (part of) Unicode character in UTF-16 encoding. Note: it is impossible to encode all Unicode code points in 2 bytes. Therefore, 2 WideChars may be needed to encode a single code point.
a |
Reference
PChar
A variable of type PChar is basically a pointer to a Char type, but allows additional operations. PChars can be used to access C-style null-terminated strings, e.g. in interaction with certain OS libraries or third-party software.
a | b | c | #0 |
^ |
Reference
PWideChar
A variable of type PWideChar is a pointer to a WideChar variable.
a | b | c | #0 | #0 | |||
^ |
Reference
String
The type string may refer to ShortString or AnsiString, depending from the {$H} switch. If the switch is off ({$H-}) then any string declaration will define a ShortString. It size will be 255 chars, if not otherwise specified. If it is on ({$H+}) string without length specifier will define an AnsiString, otherwise a ShortString with specified length.
ShortString
Short strings have a maximum length of 255 characters. The length is stored in the character at index 0.
#3 | a | b | c |
Reference
AnsiString
Ansistrings are strings that have no length limit. They are reference counted and are guaranteed to be null terminated. Internally, a variable of type AnsiString is treated as a pointer: the actual content of the string is stored on the heap, as much memory as needed to store the string content is allocated.
a | b | c | #0 | ||||||||
RefCount | Length |
Reference
UnicodeString
Like AnsiStrings UniCodeStrings are reference counted, null-terminated arrays, but they are implemented as arrays of WideChars instead of regular Chars.
a | b | c | #0 | #0 | |||||||||||
RefCount | Length |