售馨和售罄怎么读:如何控制显示内容只显示前20个字符

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 08:56:14
ASP中<%=rs(content)%>,我如何才能控制它只显示其内容的前20个字符呢?

'给你个函数,是自己写的。xstring是输入的字符,xnum是输出的字符
'2个ASCII=汉字
Function WordsLimit( xstring, xnum)
length = Len(xstring)
If (length > xnum) Then
top = xnum
tail = "…"
xx = 1
Do While (xx <= xnum)
If (Asc(Mid(xstring, xx, 1)) > 0) Then
If (xx + 1 <= length) Then
If (Asc(Mid(xstring, xx + 1, 1)) > 0) Then
xnum = xnum + 1
xx = xx + 1
End If
Else
tail = ""
Exit Do
End If
End If
If (xnum >= length) Then
tail = ""
Exit Do
End If
'If (xx > (top + yy)) Then Exit Do
xx = xx + 1
Loop
xstring = Mid(xstring, 1, xnum) & tail
End If
WordsLimit = xstring
End Function
'例:<%=WordLimit(rs(content),20)%>

function LeftStr(str,num)
if isnull(str) then
leftstr = ""
exit function
end if
str=trim(str)
if len(str)>num then
leftstr=left(str,num)+"..."
else
leftstr=str
end if
end function

<%=left(rs(content),20)%>