SUBSTRING statement
- Last Updated: January 18, 2024
- 4 minute read
- OpenEdge
- Version 12.8
- Documentation
Inserts content from a specified expression into a field or variable, optionally replacing existing characters, bytes, or columns.
Syntax
|
- target
-
A field or variable of type CHARACTER or LONGCHAR in which you want to store the specified expression.
- position
-
An integer expression that indicates the position in the target where you want to start storing the expression. If the position is longer than the target, ABL pads the target with blanks to equal the length of the position.
- length
-
An integer expression that indicates the number of positions you want to replace in the target. If you specify a length of 0, the entire expression is inserted at the position and everything else moves to the right. If you do not use the length argument or specify -1 as the length,
SUBSTRINGputs the entire expression into the target, replacing an equal amount of the target. - type
-
A character expression that directs ABL to interpret the specified position and length values as character units, bytes, or columns. A double-byte character registers as one character unit. By default, ABL interprets the specified position and length values as character units.
There are three valid type values:
"CHARACTER","RAW", and"COLUMN". The value"CHARACTER"specifies character units. The value"RAW"specifies bytes. The value"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 for a multi-byte codepage.Note: If the target is a LONGCHAR expression,"CHARACTER"is the only valid type value. - expression
-
A constant, field name, variable name, or expression of CHARACTER or LONGCHAR data type that results in a character string whose value you want to insert in the target. ABL does not pad or truncate expression.
Examples
The following 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.
r-sub.p
|
The SUBSTRING and OVERLAY statements use
the length option differently. For both, the length indicates how much of the target to replace. However, SUBSTRING always inserts the full
expression and never pads the expression to match the length. By contrast,
the length in OVERLAY determines how
much ABL adds to the target, even if ABL must truncate
the expression or pad it with spaces. The following
procedure illustrates the differences between these two statements.
r-sub-over.p
|
Notes
- Do not split double-byte characters. This statement allows you to
replace either the lead- or trail-byte of the target string when you specify
"RAW"for the type parameter.