'限定显示字符串长度 function FixStrHTML(strString,intLen) dim strS, strT dim realLen if len(strString)>realLen then strS = FixStr(strString,realLen-3) & "..." strT = strString else strS = strString strT = "" end if FixStrHTML = "<nobr><span title='" & strT & "'>" & strS & "</span></nobr>" end function'把一串字符串(包含中文)截断 Function FixStr(strSource, intLen) Dim idx Dim intL intL = 0 For idx = 1 To Len(strSource) if AscW(Mid(strSource, idx, 1)) > 256 then intL = intL + 2 Else intL = intL + 1 End If If intL > intLen Then idx = idx - 1 Exit For ElseIf intL = intLen Then Exit For End If Next FixStr = Left(strSource, idx) End Function
<td width=150 height=20>
<div style="width: 150; overflow: hidden"><%=rs("txt")%></div>
</td>
String test=rs.getString("test");
if(test!=null&&test.length>30)
test=test.substring(0,30);
out.println(test);
%>但是你这样凭空截掉,有头无尾,用户怎么看呀,是不是应该在不全的文字后面加上省略号,并提供一个链接,允许用户看到完整的信息
function FixStrHTML(strString,intLen)
dim strS, strT
dim realLen
if len(strString)>realLen then
strS = FixStr(strString,realLen-3) & "..."
strT = strString
else
strS = strString
strT = ""
end if
FixStrHTML = "<nobr><span title='" & strT & "'>" & strS & "</span></nobr>"
end function'把一串字符串(包含中文)截断
Function FixStr(strSource, intLen)
Dim idx
Dim intL
intL = 0
For idx = 1 To Len(strSource)
if AscW(Mid(strSource, idx, 1)) > 256 then
intL = intL + 2
Else
intL = intL + 1
End If
If intL > intLen Then
idx = idx - 1
Exit For
ElseIf intL = intLen Then
Exit For
End If
Next
FixStr = Left(strSource, idx)
End Function