Page History: LTrim and RTrim Functions (VB work-a-like)
Compare Page Revisions
Page Revision: 2021/02/01 11:17
The following functions return the input string with leading or trailing white-space characters (&H20 & &H09) removed.
If you need the functions for MM+, MMX, PiCromite, or ARMMite you should use the versions shown below. If you are using a MicroMite Mk2 (28 or 48 pin MX170), the below are fully compatible, but you are better off using
these versions. Being CFunctions, they are hugely faster (at least 10x and often nearer 100x) - not
precisely VB compatible as they only recognise a CHR$(32) as white space - unlikely to be a problem.
Using CONSTs and a temporary string for the compare slice gives a good speed increase.
=LTrim$(RTrim$("a"))takes only 11.5mS at 48MHz on MX170
Syntax:
LTrim$(expression)
RTrim$(expression)
Example:
a$=RTrim$(userinput$)
Code:
'preamble
Const sT$=Chr$(9), sS$=" "
Function LTrim$(a$)
Local Integer m
For m=1 To Len(a$)
If Not(Mid$(a$,m,1)=" " Or Mid$(a$,m,1)=Chr$(9)) Then LTrim$=Mid$(a$,m): Exit Function
Next
LTrim$=""
End Function
Function RTrim$(a$)
Local Integer n
For n=Len(a$) TO 1 Step -1
If Not(Mid$(a$,n,1)=" " Or Mid$(a$,n,1)=Chr$(9)) Then RTrim$=Left$(a$,n): Exit Function
Next
RTrim$=""
End Function