Это мой "варвар", но эффективное решение. это основная часть:
res :=
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
p_txt,
CHR(0),
'\0x00'
),
CHR(1),
'\0x01'
),
CHR(2),
'\0x02'
),
CHR(3),
'\0x03'
),
CHR(4),
'\0x04'
),
CHR(5),
'\0x05'
),
CHR(6),
'\0x06'
),
CHR(7),
'\0x07'
),
CHR(8),
'\0x08'
),
CHR(9),
'\0x09'
),
CHR(10),
'\0x0A'
),
CHR(11),
'\0x0B'
),
CHR(12),
'\0x0C'
),
CHR(13),
'\0x0D'
),
CHR(14),
'\0x0E'
),
CHR(15),
'\0x0F'
),
CHR(16),
'\0x10'
),
CHR(17),
'\0x11'
),
CHR(18),
'\0x12'
),
CHR(19),
'\0x13'
),
CHR(20),
'\0x14'
),
CHR(21),
'\0x15'
),
CHR(22),
'\0x16'
),
CHR(23),
'\0x17'
),
CHR(24),
'\0x18'
),
CHR(25),
'\0x19'
),
CHR(26),
'\0x1A'
),
CHR(27),
'\0x1B'
),
CHR(28),
'\0x1C'
),
CHR(29),
'\0x1D'
),
CHR(30),
'\0x1E'
),
CHR(31),
'\0x1F'
);