HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to DelphiVariablesData Types & ConversionOperatorsStringsConditions (if)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔄 Data Types & Conversion
✍️ String
🔁 Condition & Loop
🧩 Function & Procedure
Delphi›Strings

Strings

Concatenation with +, Length, UpperCase, and Copy.

Simple enough for a 5-year-old to understand

Concatenation and uppercase

Example code
1
program H;
2
{$MODE DELPHI}
3
uses SysUtils;
4
begin
5
writeln('Hex' + 'Library');
Concatenate: HexLibrary
Output / InputConcatenate: HexLibrary
6
writeln(UpperCase('hello'));
HELLO
Output / InputHELLO
7
end.
Output / Input
💡 Hint: String concatenation is done with +. UpperCase/Length require uses SysUtils.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (1 left)

1.Print the text 'hexlibrary' in UPPERCASE.

🎯 Expected output: HEXLIBRARY

Loading editor…

About this topic

In Delphi, strings are written between single quotes and are represented by a reference-counted, automatically managed type. You don't allocate or free memory; assignment and concatenation are safe.

String indices start at one. In modern Delphi, there is a compiler directive for zero-based indexing, but the default is still one; mixing the two modes leads to shifts in ported code.

Since Delphi 2009, strings are Unicode-based. This means Turkish characters work seamlessly, but you also need to know that the number of bytes and the number of characters are no longer the same.

What you will learn

  • Creating and concatenating strings
  • Length and index usage
  • Formatting function
  • Search and substring operations
  • Number and string conversion

Who is this for?

  • Processing user input
  • Formatting report output
  • Migrating to Unicode

When to use?

When assembling a variable number of parts, the formatting function is both more readable and faster than long concatenation chains.

If you are concatenating a large number of strings in a loop, using a string builder class saves you from the cost of creating a new string at every step.

Common mistakes

Wrong

var
  metin: string;
begin
  metin := 'hello';
  writeln(metin[0]);
end.

In the default mode, string indices start at one; the zeroth position is not valid, and if range checking is enabled it produces a range error, or a meaningless character if disabled. The first index must be used for the first character.

Correct

var
  metin: string;
begin
  metin := 'hello';
  writeln(metin[1]);
end.

Wrong

var
  adet: Integer;
  mesaj: string;
begin
  adet := 5;
  mesaj := 'Total: ' + adet;
  writeln(mesaj);
end.

A string and an integer cannot be concatenated directly; the compiler reports a type mismatch. You need to convert the number to a string or use a formatting function. Delphi does not perform this conversion automatically.

Correct

var
  adet: Integer;
  mesaj: string;
begin
  adet := 5;
  mesaj := Format('Total: %d', [adet]);
  writeln(mesaj);
end.

Wrong

var
  metin: string;
begin
  metin := 'hello';
  if metin = 'HELLO' then
    writeln('equal')
  else
    writeln('different');
end.

String comparison is case-sensitive, so the result will differ. To ignore case, you must use the relevant comparison function; for dotted and dotless letter pairs in Turkish, a locale-sensitive version is required.

Correct

var
  metin: string;
begin
  metin := 'hello';
  if SameText(metin, 'HELLO') then
    writeln('equal')
  else
    writeln('different');
end.

Frequently asked questions

How does the formatting function work?

Placeholders starting with a percent sign are found within the string, and values are provided as an array. There are separate specifiers for integer, floating-point, and string; an incorrect specifier throws an exception at runtime.

How do you write a quote inside a string?

By writing the single quote twice. The backslash is not an escape character in Delphi; it is a plain character within a string, which makes file paths easier.

How do I concatenate strings while keeping memory in mind?

For a small number of parts, the plus operator is sufficient. If you are concatenating hundreds of parts in a loop, since a new string will be allocated at every step, using a string list or a builder class provides a noticeable speed gain.

Summary

Strings are written in single quotes and are automatically managed.

Indices start at one by default.

Numbers are included in strings with explicit conversion.

The formatting function uses placeholders.

Comparison is case-sensitive.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code