ASP向右读字数

来源:百度知道 编辑:UC知道 时间:2024/05/22 09:09:55
比如新闻的标题,有的标题特别长,表格的行就变形了。

我想做一个只读取10个字符,如果多余就显示...,如果小于10个字符,就正常显示,不要点点点!

<%if len(rs("title"))>10 then%>
<%=left(rs("title"),9)%>...
<%else%>
<%=rs("title")%>
<%end if%>

<%
Function CutString(ByVal str, ByVal strlen, ByVal char)
Dim t,c,i
t = 0
For i = 1 to len(str)
c = Abs(Ascw(Mid(str,i,1)))
t = IIF(c > 255,t + 2,t + 1)
If t >= strlen Then
CutString = Left(str,i) & char
Exit For
Else
CutString = str
End If
Next
CutString = Replace(CutString,chr(10),"")
End Function
%>
<%=CutString(标题,10,"...")%>
用这个函数

<%
'======================================
'取左边N个字符,1个中文字符=2个英文字符
'参数:字符串,左边字符数,超出部分的连接字符串
'======================================
function leftstr(title,n,nexttext)
dim f_title,f_i,f_k,f_a
f_title=""
f_k=0
dim re
for f_i=1 to len(title)
f_