Previous section   Next section


A string function that returns a string of spaces.


{fn SPACE(count)}


count An integer expression specifying the number of blank spaces to return.


SPACE returns a string of blank spaces count spaces long. If count is a numeric string, a decimal number, or a mixed numeric string, Caché resolves it to its integer portion. If count is a negative number or a nonnumeric string, Caché resolves it to 0.
To remove blank spaces from a string, use LTRIM (leading blanks) or RTRIM (trailing blanks).
The SPACE function should not be confused with the SPACE collation type. SPACE collation appends a single space to a value, forcing it to be evaluated as a string. To establish SPACE collation, CREATE TABLE provides a %SPACE collation keyword, and ObjectScript provides the Collation() method of the %SYSTEM.Util class.


The following embedded SQL example returns a string of spaces the length of the name field:
   &sql(SELECT SPACE(LENGTH(name))
   INTO :a
   FROM Sample.Person)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE }
   ELSE {
     WRITE !,"Leave this much space:",a,"for names" }

See Also

Previous section   Next section