Q(uick)BASIC Function: RTRIM$
Quick View
RTRIM$
A string processing function that returns a string with trailing (right-hand) spaces removed
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- LTRIM$(stringexpression$)
- RTRIM$(stringexpression$)
Description/Parameter(s)
stringexpression$ | Any string expression. |
Example
a$ = " Basic "
PRINT "*" + a$ + "*" 'Output is: * Basic *
PRINT "*" + LTRIM$(a$) + "*" 'Output is: *Basic *
PRINT "*" + RTRIM$(a$) + "*" 'Output is: * Basic*
Syntax
- RTRIM$(stringexpression)
Description/Parameter(s)
The stringexpression can be any string expression.
The RTRIM$ function works with both fixed- and variable-length string variables.
Example
This example shows the effects of RTRIM$ on fixed- and variable-length strings.
DIM FixStr AS STRING * 10
CLS ' Clear screen
PRINT " 1 2"
PRINT "12345678901234567890"
FixStr = "Twine"
PRINT FixStr + "*"
PRINT RTRIM$(FixStr) + "*"
VarStr$ = "Braided" + SPACE$(10)
PRINT VarStr$ + "*"
PRINT RTRIM$(VarStr$) + "*"
Sample Output:
1 2 12345678901234567890 Twine * Twine* Braided * Braided*See also:
Syntax
- RTRIM$(stringexpression$)
Description/Parameter(s)
Usage Notes
- The argument stringexpression$ can be any string expression.
- The RTRIM$ function works with both fixed- and variable-length string variables.
Example
This example uses the STR$ function to convert a number to its string representation and the LTRIM$ and RTRIM$ functions to strip out the leading and trailing blanks that BASIC ordinarily prints with numeric output.
CLS 'Clear the screen.
PRINT "Enter 0 to end."
DO
INPUT "Find cosine of: ", Num
IF Num = 0 THEN EXIT DO
X$ = STR$(Num)
NumRemBlanks$ = LTRIM$(RTRIM$(X$))
PRINT "COS("; NumRemBlanks$; ") = "; COS(Num)
LOOP
Sample Output:
Enter 0 to end. Find cosine of: 3.1 COS(3.1) = -.9991351 Find cosine of: 0See also: