Substr Function

Action

Extracts a substring (nLen characters in length, beginning at position nStart) from a string.

If the start position is not within the string an error is raised. If the length specification exceeds the string’s length, the substring ends with the last character of the string.

Include file

Kernel.bdh

Syntax

Substr( in  sSource : string,
        out sDest   : string,
        in  nStart  : number,
        in  nLen    : number): string;

Return value

copied substring

Parameter Description
sSource Source string
sDest Destination string
nStart Position of first character
nLen Length of substring

Example

dcltrans
  transaction TSubstr
  var
    sString, sPart: string;
  begin
    sString := "Hello world!";
    write("string = "); write(sString); writeln;
    // extract substring "world"
    Substr(sString, sPart, 7, 5);
    write("part = "); write(sPart); writeln;
  end TSubstr;

Output

string = Hello world!
part = world