5 TRIM$

This routine trims whitespace (spaces, tabs, carriage returns and line-feeds) from the start and end of a string.

A%=5:CALL&4083,string$

All arguments are passed by reference. You may pass multiple strings at a time. Both movable strings and fixed strings are supported; all other types are ignored.

The following program:

10 str$="  Hello  "
20 A%=5:CALL&4083,str$
30 PRINT "<"+str$+">"

would output:

<Hello>

BASIC wrapper function

You can wrap up the routine as a standard BASIC function using the following snippet:

DEFFN_TRIM$(s$)LOCALA%:A%=5:CALL&4083,s$:=s$

You could then invoke it like this:

PRINT "<"+FN_TRIM$("  Hello  ")+">"

which would output

<Hello>

See Also