Progress
Language Reference


SUBSTRING Statement

Interfaces
OS
SpeedScript
All
All
Yes

Replaces characters in a field or variable with an expression you specify.

SYNTAX

SUBSTRING 
  ( source , position [ , length [ , type ] ] ) = expression 

source

A field or variable that you want to store as expression.

position

An integer expression that indicates the position in source in which you want to start storing expression. If position is longer than source, Progress pads source with blanks to equal the length of position.

length

An integer expression that indicates the number of positions you want to replace in source. If you specify a length of 0, the 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, SUBSTRING puts the entire expression into source, replacing everything in source necessary to make room for expression.

type

A character expression that directs Progress 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, Progress interprets the specified position and length 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, Progress validates the type specification at compile time. If you specify the type as a non-constant expression, Progress validates the type specification at run time.

expression

A constant, field name, variable name, or expression that results in a character string whose value you want to store in source. Progress does not pad or truncate expression.

EXAMPLE

The 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.

r-sub.p
DEFINE VARIABLE rtext AS CHARACTER FORMAT "x(50)" .
DEFINE VARIABLE orig AS CHARACTER FORMAT "x(31)".
DEFINE VARIABLE strt AS INTEGER FORMAT ">9".
DEFINE VARIABLE leng AS INTEGER FORMAT ">9".

orig = "Now is the time to use PROGRESS".
DISPLAY orig WITH CENTERED TITLE "Original Text" NO-LABEL.
REPEAT:
  rtext = orig.
  UPDATE strt LABEL "START" leng LABEL "LENGTH".
  SUBSTRING(rtext,strt,leng,"CHARACTER") = "XXXXXXXXX".
  DISPLAY rtext LABEL "WORD" WITH CENTERED.
END. 

NOTES

SEE ALSO

OVERLAY Statement, SUBSTRING Function


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095