Q(uick)BASIC Function: SPACE$

Quick View

SPACE$

A string processing function that returns a string of spaces of length n

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • SPACE$(n%)
Description/Parameter(s)
n% The number of spaces you want in the string.
Example
FOR i% = 1 TO 5 x$ = SPACE$ (i%) PRINT x$; i% NEXT i%
Syntax
  • SPACE$(n)
Description/Parameter(s)

The expression n is rounded to an integer and must be in the range 0-32,767, where n is the number of spaces you want in the string.

Example
CLS ' clear the screen FOR I=1 TO 5 X$=SPACE$(I) PRINT X$;I NEXT I

Sample Output:

1 2 3 4 5
Syntax
  • SPACE$(n)
Description/Parameter(s)
n A numeric expression that specifies the number of spaces you want in the string. The expression is rounded to an integer and must be between 0 and 32,767, inclusive.
Example

This example uses the SPACE$ function to create a string of spaces (ASCII 32). The program inserts the spaces on a printed line before the number of spaces that the string contains.

CLS 'Clear the screen. FOR I = 1 TO 5 X$ = SPACE$(I) PRINT X$; I NEXT I

Sample Output:

1 2 3 4 5