SUBSTRING statement
Inserts content from a specified expression into a field or variable, optionally replacing existing characters, bytes, or columns.
Syntax
target
position
length
An integer expression that indicates the number of positions you want to replace in thetarget
. If you specify a length of 0, the entireexpression
is inserted at theposition
and everything else moves to the right. If you do not use thelength
argument or specify -1 as the length, SUBSTRING puts the entireexpression
into thetarget
, replacing an equal amount of thetarget
.type
A character expression that directs ABL to interpret the specifiedposition
andlength
values as character units, bytes, or columns. A double-byte character registers as one character unit. By default, ABL interprets the specifiedposition
andlength
values as character units.There are three valid types: "CHARACTER," "RAW,".and "COLUMN." The expression "CHARACTER" specifies character units. The expression "RAW" specifies bytes. The expression "COLUMN" specifies display or print character-columns. If you specify the type as a constant expression, ABL validates the type specification at compile time. If you specify the type as a non-constant expression, the AVM validates the type specification at run time.Note: If thetarget
is a LONGCHAR expression, "CHARACTER" is the only valid type.expression
ExamplesThe r-sub.p procedure uses the SUBSTRING statement to replace a segment of text with the expression in the SUBSTRING statement XXXXXXXXX. The procedure first displays the text you can work with in the Original Text frame. Then the procedure prompts you for the start position of the replacement and the length of the replacement. Under the WORD heading, you see the revised text.
The SUBSTRING and OVERLAY statements use the
length
option differently. For both, thelength
indicates how much of thetarget
to replace. However, SUBSTRING always inserts the fullexpression
and never pads theexpression
to match thelength
. By contrast, thelength
in OVERLAY determines how much ABL adds to thetarget
, even if ABL must truncate theexpression
or pad it with spaces. The r-sub-over.p (1 of 2) procedure illustrates the differences between these two statements.
NoteSee also
OpenEdge Release 10.2B
|