<%
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)
%>
显示结果:
你好我好...