Skip to main content

BreakStringTail

Procedure BreakStringTail(S: string; const aSep: string; var Head, Tail: string)

Example

procedure ScriptEvent(var Value: variant);
var
Head, Tail: string;
begin
BreakStringTail('segment/rest/of/path', '/', Head, Tail);
Value := Head + ' / ' + Tail; // segment / rest/of/path
end;

Usage

BreakStringTail splits text around the first exact separator substring and preserves the unsplit input in Tail when no match exists.

Parameters

NameModeDescription
SinputSource text; not modified.
aSepinputCase-sensitive separator substring. Multi-character values are supported.
Headoutput through varText before the first separator, or empty when no separator exists.
Tailoutput through varText after the complete separator, or all of S when no separator exists.

The procedure overwrites both output variables and returns no value.

Additional Technical Info

BreakStringTail splits S at the first exact occurrence of aSep, discarding the separator. Its distinguishing rule is the no-match case: Head becomes empty and the complete original input is placed in Tail.

The example is fictional and source-reviewed only.

Exact results

Input situationHeadTail
'A::B::C', separator '::''A''B::C'
'::A', separator '::''''A'
'A::', separator '::''A'''
'ABC', separator '::''''ABC'
'ABC', empty separator'''ABC'

The implementation uses literal, case-sensitive Delphi Pos and Copy. It does not interpret a regular expression, delimiter set, quoting or escape sequences, and only the first occurrence is consumed.

Use BreakString when the no-match input should be returned through Head instead.

Created 2026-07-15