RTrm$: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:


  RTrm$(AS[,"char"])
  RTRM$(<string>[,"character"])


The '''RTrm$''' [[internal function]] returns A$, deleting all trailing blanks. So named, because it Right TRiMs the blanks from the string in A$.
The '''RTrm$''' [[internal function]] returns the string, deleting all trailing blanks. So named, because it Right TRiMs the blanks from the string.


An optional second parameter ("char") has been added to LTRM$ and RTRM$ to specify the character to strip (instead of blanks, which are still the default). The "char" parameter is limited to one character in length (error 0410 will result if it is longer). Nulls and CHR$(0) are allowed. The following statement would return the value 12:
An optional second parameter ("character") has been added to LTRM$ and RTRM$ to specify the character to strip (instead of blanks, which are still the default). The "character" parameter is limited to one character in length (error 0410 will result if it is longer). Nulls and CHR$(0) are allowed. The following statement would return the value 12:


  PRINT RTRM$("1200","0")
  PRINT RTRM$("1200","0")

Latest revision as of 00:58, 22 May 2014

RTRM$(<string>[,"character"])

The RTrm$ internal function returns the string, deleting all trailing blanks. So named, because it Right TRiMs the blanks from the string.

An optional second parameter ("character") has been added to LTRM$ and RTRM$ to specify the character to strip (instead of blanks, which are still the default). The "character" parameter is limited to one character in length (error 0410 will result if it is longer). Nulls and CHR$(0) are allowed. The following statement would return the value 12:

PRINT RTRM$("1200","0")

Comments and Examples

RTRM$ can be used to delete extra spaces when formatting an address to CITY, STATE. Line 530 will always allow 18 columns for CITY$ and print the comma in column 19, regardless of the number of non-blank characters in the string. Since RTRM$ is used in line 540, the comma will print immediately after the last non-blank character in CITY$.

00510 READ #2,USING 520: CITY$, STATE$
00520 FORM C 18, C 2
00530 PRINT CITY$;", ";STATE$
00540 PRINT RTRM$(CITY$);", ";STATE$

When the file contains Minneapolis and MN, the output will be:

Minneapolis , MN
Minneapolis, MN

Related Functions

See LTRM$ to trim blanks from the left and LPAD$ and RPAD$ to add blanks.

Technical Considerations

  1. To remove blanks from strings read from a formatted file or screen, V format is an alternative to RTRM$. Reading X$ with V format is equivalent to reading X$ with C format, then doing X$=RTRM$(X$). For example, lines 520 and 540 in the Comments and Examples section above could be changed as follows and still achieve the same results:
00520 FORM V 18, C 2
00540 PRINT CITY$;", ";STATE$