SUBSTRDW(), SUBSTRDWS()

SUBSTRDW(), SUBSTRDWS()

Top  Previous  Next

 

The SUBSTRDW() function extracts a substring based on its display width. The SUBSTRDWS() function is similar but operates on successive elements of a dynamic array, returning a similarly structured dynamic array of results.

 

 

Format

 

SUBSTRDW(string, start, length)

SUBSTRDWS(string, start, length)

 

where

 

stringis the string from which a substring is to be extracted.

 

startevaluates to the start character position. A start position less than one is treated as one.

 

lengthevaluates to the length of the substring to be extracted based on its display width. A negative substring length is treated as zero.

 

 

On an ECS mode system, some characters may require two columns for display or printing. The SUBSTRDW() function extracts a substring that will require len columns for display. If the substring extends beyond the end of string, the returned data will be shorter than the limit specified by the length argument.

 

On a non-ECS system, this function is equivalent to use of the standard substring operator string[start, length].

 

 

 

Example

 

I = 1

LOOP

  S = SUBSTRDW(TEXT, I, 30)

UNTIL S = ""

  DISPLAY S

  I += LEN(S)

REPEAT

 

This program fragment displays the data in TEXT as a series of lines that fit a display width of 30 columns. Note how the start position index, I, is incremented by the number of characters in each substring instead of the display width.

 

 

See also:

DISPLAY.WIDTH()