Skip to main content

RightStr

Function RightStr( const AText : AnsiString; const ACount : Integer) : AnsiString

Example

procedure ScriptEvent(var Value: variant);
begin
Value := RightStr('INV-0042', 4); // 0042
end;

Usage

RightStr returns up to a requested number of trailing characters through the explicitly imported ANSI StrUtils overload.

Important behavior and quirks

  • Conversion into AnsiString uses the active code page. Characters not representable in that code page can be lost or substituted before slicing.
  • ACount is interpreted in ANSI character/index terms of the selected overload. In a multibyte code page, character and byte counts are not interchangeable.
  • The function does not trim whitespace and does not mutate the input.
  • Use Copy when the starting position must be explicit.

Additional Technical Info

RightStr returns the rightmost ACount characters of AText. The generated Velox import explicitly selects the AnsiString overload, matching the import comment that LeftStr, RightStr and MidStr must remain ANSI.

The example is fictional and source-reviewed only.

Return rule

The Delphi terminal executes:

Copy(AText, Length(AText) + 1 - ACount, ACount)
ConditionResult
ACount <= 0Empty string.
0 < ACount < Length(AText)Exactly the requested trailing characters.
ACount >= Length(AText)Complete input.
Empty inputEmpty string.

Performance and concurrency

The result is one bounded copy. Code-page conversion may occur at the script/native boundary; there is no mutable Velox state.

External references

Created 2026-07-15