Progress
Language Reference


LENGTH Function

Interfaces
OS
SpeedScript
All
All
Yes

Returns the number of characters, bytes, or columns in a string. Returns the number of bytes in an expression of type RAW.

SYNTAX

LENGTH ( { string [ type ] | raw-expression } ) 

string

A character expression. The specified string can contain double-byte characters.

type

A character expression that indicates whether you want the length of a string in character units, bytes, or columns. A double-byte character registers as one character unit. By default unit of measurement is character units.

There are three valid types: "CHARACTER," "RAW," and "COLUMN." The expression "CHARACTER" indicates that the length is measured in characters, including double-byte characters. The expression "RAW" indicates that the length is measured in bytes. The expression "COLUMN" indicates that the length is measured in 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.

raw-expression

A function or variable name that returns a raw value.

EXAMPLES

This procedure produces a report that contains item information. Because the information on the report fills the entire width of the screen, this procedure shortens the information in the description field for each item. If the description of an item is longer than eight characters, the procedure converts the description to the first eight characters followed by ellipses.

r-length.p
DEFINE VARIABLE short-name AS CHARACTER
    FORMAT "x(11)" LABEL "Desc".

FOR EACH item:
    IF LENGTH(item-name, "CHARACTER") > 8 THEN
        short-name = SUBSTRING(item-name,1,8, "FIXED") + "..." .
    ELSE short-name = item-name.
    DISPLAY item-num short-name on-hand allocated
            re-order on-order price FORMAT "$>>>9.99".
END. 

In this procedure, the LENGTH function returns the number of bytes in the name of number 29. The procedure returns a 15, the number of bytes in the name, Bug in a Rug-by.

r-rawlen.p
DEFINE VARIABLE i AS INTEGER.

FIND customer WHERE Cust-num = 29.
i = LENGTH(name, "RAW").
DISPLAY Name i LABEL "Byte Length". 

NOTE

LENGTH of the unknown value is the unknown value (?).


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