Page History: LTrim and RTrim Functions (VB work-a-like)
Compare Page Revisions
Page Revision: 2018/01/22 12:26
The following functions return the input string with leading or trailing white-space characters (&H20 & &H09) removed.
Similar CFunctions have been written and you should consider these as they offer an increase in speed. They do, however, recognise only character &H20 (space) as white-space - TABs will not be removed. Also, they are not compatible with MMX platforms.
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