Skip to main content

Pos

function Pos(SubStr, S: String): LongInt;

Example

procedure ScriptEvent(var Value: variant);
begin
Value := Pos('EDI', 'Velox EDI'); // 7
end;

Usage

Returns the one-based position of the first exact, case-sensitive substring match, or zero when no non-empty match exists.

Parameters and result

ItemTypeDescription
SubStrStringNon-empty text to locate.
SStringSource text to search.
ResultLongIntFirst one-based match position, or 0.

Matching is case-sensitive, ordinal and non-regex. 'edi' does not match 'EDI'. In Velox, an empty SubStr returns 0, including against an empty source. A non-empty substring longer than S also returns 0.

ANSI, WideString and UnicodeString values are supported. Arguments must be compatible string values. No locale-based case folding or Unicode normalisation is performed.

Positions are code-unit indexes. If the string carries multibyte ANSI text or UTF-16 surrogate pairs, the number is not necessarily a user-perceived character index. Check explicitly for > 0 before using the result as a position; subtracting or passing a not-found zero into another one-based routine can produce unintended boundary behavior.

Use PosEx when the search must start at a caller-specified offset. Use IndexText for a case-insensitive whole-value lookup in an array.

Additional Technical Info

Pos searches S from its beginning for the first exact occurrence of SubStr. It returns the one-based starting position or 0 when no match exists.

The example is fictional and source-reviewed only.

External references

Created 2026-07-15