请问如果要读出字节的内容,rs有什么函数可代替??

来源:百度知道 编辑:UC知道 时间:2024/06/02 11:06:19
ASP网页制作遇室如下问题,当标题大于60个字节时,读取前60个字节的内容,但RS读取以字符计,半角全角都按一个字算,结果读出来的标题有长有短,请问如果要读出前60个字节的内容,rs有什么函数可代替??

<%if lenb(rs("title"))>60then%>
<%=left(rs("title"),30)%>......
<%else%>
<%=rs("title")%>
<%end if%>
如:

123456789012345678901234567890......

123456789012345678901234567890......

123456789012345678901234567890

规规规规规规规规规规规规规规规规规规规规规规规规规24规规规......

规规规规规规规规规规规规规规规规规规规规规规规规规24规规规......

规规规规规规规规规规规规规规规规规规规规规规规规规24

<%
function cutstr(tempstr,tempwid)
if len(tempstr)>tempwid then
cutstr=left(tempstr,tempwid)&"..."
else
cutstr=tempstr
end if
end function%>
<%=cutstr(rs("title"),25)%>
试一下吧!

首先不可以按
半角按一个字算,全角都按两个字算
这根本不可能完全达到 2个半角=1个全角
所以以下方法也是不可以的,不过可以一试

'/////////////////////
'*************************************************************
'函数作用:显示字符串长度
'*************************************************************
Public Function gotTopic(Str, strlen)
Dim l, T, c, i
Str = Replace(Str, " "," ")
l = Len(Str)
T = 0
For i = 1 To l
c = Abs(Asc(Mid(Str, i, 1)))
If c > 255 Then
T = T + 2
Else
T = T + 1
End If
If T >= strlen Then
gotTopic = Left(Str, i) & "..."
Exit For
Else
gotTopic = Str & " "
End If
Ne