Can the Ltrim command remove also other character than space?
For example:
string="--fdfd--"
using command
ltrim(string,'-')
could it remove the leading '-' characters?
REM ***** BASIC *****
Function myLTrim(InputStr as string, StrToTrim as string) as String
If Left(InputStr, Len(StrToTrim)) = StrToTrim then
myLTrim = Right(InputStr, Len(InputStr)-Len(StrToTrim))
else
myLTrim = InputStr
end if
End function
Sub Main
st = "--fdfd--"
msgbox LTrimAny (st,"-")
msgbox RTrimAny(st,"-")
msgbox TrimAny(st,"-")
End Sub
function LTrimAny(byval st,trimchar)
dim c as long,i as long
for i = 1 to len(st)
if mid(st,i,1)= trimchar then
c = c+1
else
exit for
end if
next
if c>0 then mid(st,1,c) =""
LTrimAny= st
end function
function RTrimAny(byval st,trimchar)
dim c as long,i as long,lenst
lenst= len(st)
for i = lenst to 1 step -1
if mid(st,i,1)= trimchar then
c = c+1
else
exit for
end if
next
if c>0 then mid(st,lenst -c+1,c) =""
RTrimAny= st
end function
function TrimAny(byval st,trimchar)
st=LTrimAny(st,trimchar)
TrimAny=RTrimAny(st,trimchar)
end function
=PYSTRING("lstrip";A1;"-")
Sub Main
st = "--fdfd--"
msgbox LTrimAny (st,"-")
msgbox RTrimAny(st,"-")
msgbox TrimAny(st,"-")
End Sub
function LTrimAny(byval st,trimchar)
dim i as long
for i = 1 to len(st)
if mid(st,i,1)<> trimchar then exit for
next
if i>1 then mid(st,1,i-1) =""
LTrimAny= st
end function
function RTrimAny(byval st,trimchar)
dim i as long,lenst as long
lenst = len(st)
for i = lenst to 1 step -1
if mid(st,i,1)<> trimchar then exit for
next
if i< lenst then mid(st,i+1,i-lenst) =""
RTrimAny= st
end function
function TrimAny(byval st,trimchar)
st=LTrimAny(st,trimchar)
TrimAny=RTrimAny(st,trimchar)
end function
Function withoutJunkLeft( pString As String, pJunk As String)
l = Len(pJunk)
pos = 1
While InStr(pos, pString, pJunk, 0)=pos
pos = pos + l
Wend
withoutJunkLeft = Mid(pString, pos, 65535)
End Function
Function withoutJunkRight( pString As String, pJunk As String)
l = Len(pJunk)
pos = Len(pString) - l + 1
While InStr(pos, pString, pJunk, 0)=pos
pos = pos - l
Wend
withoutJunkRight = Left(pString, pos+l-1)
End Function
Sub Main
st = "-q-fdfd--"
msgbox LTrimAny (st,"f-pq")
msgbox RTrimAny(st,"p-")
msgbox TrimAny(st,"-q")
End Sub
function LTrimAny(byval st,trimchars)
dim i as long
for i = 1 to len(st)
if instr(1, trimchars, mid(st,i,1)) = 0 then exit for
next
if i>1 then mid(st,1,i-1) =""
LTrimAny= st
end function
function RTrimAny(byval st,trimchars)
dim i as long,lenst as long
lenst = len(st)
for i = lenst to 1 step -1
if instr(1, trimchars, mid(st,i,1)) = 0 then exit for
next
if i< lenst then mid(st,i+1,i-lenst) =""
RTrimAny= st
end function
function TrimAny(byval st,trimchars)
st=LTrimAny(st,trimchars)
TrimAny=RTrimAny(st,trimchars)
end function
Users browsing this forum: No registered users and 4 guests