您的位置:首页 > 编程语言 > ASP

asp中自定义截取字段函数StrLeft()

2008-11-01 20:37 363 查看
<%

function StrLeft(Str,StrLen)
dim L,T,I,C
if Str="" then
StrLeft=""
exit function
end if
Str=Replace(Replace(Replace(Replace(Str," "," "),""",Chr(34)),">",">"),"<","<")
L=Len(Str)
T=0
for i=1 to L
C=Abs(AscW(Mid(Str,i,1)))
if C>255 then
T=T+2
else
T=T+1
end if
if T>=StrLen then
StrLeft=Left(Str,i) & "…"
exit for
else
StrLeft=Str
end if
next
StrLeft=Replace(Replace(Replace(replace(StrLeft," "," "),Chr(34),"""),">",">"),"<","<")
end function

例:

aa="你好我好大家好他好她好人人好"

bb=StrLeft(aa,4)

response.write(bb)

%>

显示结果:

你好我好...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: