当我们在做列表显示的时候,有时列表内容长度超过列表宽度就可能换行或者把结构挤爆,此时我们可以通过下面的方法对超长字符串进行截断。
txt=trim(varString) 'varString可以是固定的字符串,也可以是从数据库读取的数据
y=0
for i=1 to len(txt)
j=mid(txt,i,1)
if asc(j)>=0 and asc(j)<=127 then '汉字外的其他符号,如:!@#,数字,大小写英文字母
y=y+0.5
else '汉字
y=y+1
end if
if -int(-y) >= 25 then '截取长度
txt = left(txt,i)
exit for
end if
Next
response.write txt
If varString<> txt Then
response.write("…")
End if