Page History: LTrim and RTrim Functions (VB work-a-like)
Compare Page Revisions
Page Revision: 2018/01/04 18:55
The following functions return the input string with leading or trailing white-space characters (&h20 & &h09) removed
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