Asp编程 怎样实现:从数据库中读出数据,只显示前n的字符,…

来源:百度知道 编辑:UC知道 时间:2024/06/06 12:10:03
Asp编程 怎样实现:从数据库中读出数据,只显示前n的字符,…

使用方法:
cutstr(rs("title"),20,1) ‘20是显示20个字符,1是加省略号

'//字符串截取函数(按半角)
'//flag—1为加省略号,0不加
Function cutstr(str,length,flag)
Dim l,t,c,i
l=Len(str)
t=0
if l>=1 then
For i=1 To l
c=AscW(Mid(str,i,1))
If c<0 Or c>255 Then t=t+2 Else t=t+1
IF t>=length Then
if flag=1 then
cutstr=left(str,i)&"..."
Exit For
else
cutstr=left(str,i)
Exit For
end if
Else
cutstr=str
End If
Next
else
cutstr=""
end if
End Function

Left(rs("字段名"), 10) 表示前10个字符