asp中截取字符串的方法
<%
Function Strsub(str,lennum,s)
If Not IsNull(str) Then
Dim p_num,x
Dim i
If len(str)<=lennum Then
Strsub=str
Else
p_num=0
x=0
Do While Not p_num > lennum-2
x=x+1
If Asc(Mid(str,x,1))<0 Then
p_num=Int(p_num) + 2
Else
p_num=Int(p_num) + 1
End If
Strsub=Left(Trim(str),x)&s '截取后定义超出部分内容的显示方式
Loop
End If
Else
Strsub="Null"
End If
End Function
%>
调用方法
<%= Strsub(“aaaaaaaaaaaaaa”,15,"...")%>
<%
'截取字符串函数
function cutstr(thestr1,strlen)
dim l,t,c
l=len(thestr1)
if l<1 then exit function
t=0
for dxy1=1 to l
c=Abs(asc(Mid(thestr1,dxy1,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=strlen then
thev=mid(thestr1,1,dxy1)&".."
exit for
else
thev=thestr1
end if
next
cutstr=thev
end function
%>
浙公网安备 33010602011771号