Q(uick)BASIC Function: STRING$

Quick View

STRING$

A string processing function that returns a string whose characters all have a given ASCII code or whose characters are all the first character of a string expression

Worth knowing

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

Syntax
  • STRING$(length%,{ascii-code% | stringexpression$})
Description/Parameter(s)
length% The length of the string.
ascii-code% The ASCII code of the repeating character.
stringexpression$ Any string expression. STRING$ fills the string with the first character in stringexpression$.
Example
PRINT STRING$(5, "-"); PRINT "Hello"; PRINT STRING$(5, "-")
Syntax
  • STRING$(m,n)
  • STRING$(m,stringexpression)
Description/Parameter(s)
Argument Description
m A numeric expression indicating the length of the string to return.
n The ASCII code of the character to use to build the string. It is a numeric expression that evaluates to an integer value in the range 0-255.
stringexpression The string expression whose first character is used to build the return string.
Examples

The following example uses STRING$ to create part of a report heading:

Dash$ = STRING$(10,45) PRINT Dash$;"MONTHLY REPORT";Dash$

Sample Output:

----------MONTHLY REPORT----------

The following program uses STRING$ to generate a bar graph:

PRINT TAB(7);"Daily Mean Temperature in Seattle" 'Get data for each month and graph. FOR Month = 1 TO 12 STEP 2 READ Month$, Temp 'Print Temp-35 stars. PRINT Month$;" +"; STRING$(Temp-35,"*") PRINT " |" NEXT Month 'Print horizontal line. PRINT " +"; FOR X = 1 TO 7 PRINT "----+"; NEXT X PRINT 'Print temperature labels. FOR X = 4 TO 39 STEP 5 PRINT TAB(X); X+31; NEXT X PRINT DATA Jan, 40, Mar, 46, May, 56 DATA Jul, 66, Sep, 61, Nov, 46

Sample Output:

Daily Mean Temperature in Seattle Jan +***** | Mar +*********** | May +********************* | Jul +******************************* | Sep +************************** | Nov +*********** | +----+----+----+----+----+----+----+ 35 40 45 50 55 60 65 70
Syntax
  • STRING$(m%,n%)
  • STRING$(m%,stringexpression$)
Description/Parameter(s)
m% A numeric expression indicating the length of the string to return.
n% An integer expression with a value between 0 and 255 that is the ASCII character code of the character that fills the string.
stringexpression$ A string whose first character fills the string.
Example

This example uses the STRING$ function to generate a bar graph.

CLS PRINT TAB(7); "Daily Mean Temperature in Seattle" PRINT 'Get data for each month and graph. FOR Month = 1 TO 12 STEP 2 READ Month$, Temp 'Print Temp-35 stars. PRINT Month$; " +"; STRING$(Temp - 35, "*") PRINT " |" NEXT Month 'Print horizontal line. PRINT " +"; FOR X = 1 TO 7 PRINT "----+"; NEXT X PRINT 'Print temperature labels. FOR X = 4 TO 39 STEP 5 PRINT TAB(X); X + 31; NEXT X PRINT DATA Jan, 40, Mar, 46, May, 56 DATA Jul, 66, Sep, 61, Nov, 46

Sample Output:

Daily Mean Temperature in Seattle Jan +***** | Mar +*********** | May +********************* | Jul +******************************* | Sep +************************** | Nov +*********** | +----+----+----+----+----+----+----+ 35 40 45 50 55 60 65 70