ASP去掉字符串头尾的连续的回车和空格函数trimVBcrlf
有时网站编辑输入文字时,需要去掉字符串头尾的连续的回车和空格,以下函数(ASP trimVBcrlf)实现去字符功能:
<%
'去掉字符串头尾的连续的回车和空格
Function trimVBcrlf(str)
trimVBcrlf=rtrimVBcrlf(ltrimVBcrlf(str))
End Function
'去掉字符串开头的连续的回车和空格
Function ltrimVBcrlf(str)
Dim pos,isBlankChar
pos=1
isBlankChar=true
While isBlankChar
If mid(str,pos,1)=" " then
pos=pos+1
ElseIf mid(str,pos,2)=VBcrlf then
pos=pos+2
Else
isBlankChar=false
End if
Wend
ltrimVBcrlf=right(str,len(str)-pos+1)
End Function
'去掉字符串末尾的连续的回车和空格
Function rtrimVBcrlf(str)
Dim pos,isBlankChar
pos=len(str)
isBlankChar=true
While isBlankChar and pos>=2
If mid(str,pos,1)="" then
pos=pos-1
ElseIf mid(str,pos-1,2)=VBcrlf then
pos=pos-2
Else
isBlankChar=false
End if
Wend
rtrimVBcrlf=rtrim(left(str,pos))
End Function
%>