Chapter 5 – String Handling
Chapter 5 provides a comprehensive guide to string manipulation, character types, and Unicode support in Delphi XE2. It covers the core string type, its behaviour as a reference type that acts like a value type, and the practical implications for indexing and length operations.
The String Type
Delphi's string type is a reference type that behaves like a value type, offering copy-on-write semantics. The chapter explains string indexing, how to return length information via Length and ByteLength, and surveys other string types including legacy string types carried forward from earlier Delphi versions.
Character Types
This section examines the Char type in detail — its literals, constants, and how to work with individual character values. The TCharacter type is introduced as a utility for inspecting and classifying Unicode characters, reflecting Delphi XE2's full Unicode foundation.
String Manipulation Routines
A substantial portion of the chapter is devoted to the standard string manipulation routines available in the Delphi runtime library:
- Creating repeating strings with
StringOfCharandDupeString - Comparing complete strings using the equality operator,
CompareStr,CompareText, and related functions - Searching, extracting, and replacing substrings
- Case conversion and whitespace trimming
TStringBuilder
The TStringBuilder class is covered as an efficient alternative for building strings through repeated concatenation. The chapter also discusses TStringList and TStrings for managing collections of strings, along with regular expression support and advanced Unicode handling available in Delphi XE2.