求助asp高手问题....帮实现一个小功能..谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/27 19:11:09
<script language=javascript>
Function RealStrLength(str)
ON ERROR RESUME NEXT
dim slen,total,code,i
slen=len(str) '先调用len函数计算长度
total=slen '给total赋值
'逐个取出字符判断,超出ASCII范围则总长度加一
for i=1 to slen
code=asc(mid(str,i,1))
if code>255 and code<0 then
total=total+1
end if
next
RealStrLength=total
end if
End Function
</script>

以上代码我不知道怎么用...可以参考一下..

<%
if len(trim(rs("newsname")))>11 then
response.write left(trim(rs("newsname")),11)&".."
else
response.write trim(rs("newsname"))
end if
%>
数据库中表:newsname
有中英文混合的语句...
现在显示的结果是:
----------------------------
英文显示是:12345678911..
中文显示是:一二三四五六七八九十十..
----------------------------
这样显示很不好看.

最上面的函数是这样的:
<script language=vbscript runat=server>
Function RealStrLength(str)
ON ERROR RESUME NEXT
dim slen,total,code,i
slen=len(str) '先调用len函数计算长度
total=slen '给total赋值
'逐个取出字符判断,超出ASCII范围则总长度加一
for i=1 to slen
code=asc(mid(str,i,1))
if code>255 and code<0 then
total=total+1
end if
next
RealStrLength=total
end if
End Function
</script>
下面这段代码没有什么意义啊,呵呵,只要长度大于11,还是中文截取11个,英文截取11个,不一样长的,所以用leftb代替left吧。
<%
if RealStrLength(trim(rs("newsname")))>11 then
'response.write left(trim(rs("newsname")),11)&".."
'将上面的改成
response.write leftb(trim(rs("newsname")),10)&".." '用11有一个缺点,那就是中文和英文还是不一样宽,而且用11这个函数有问题,一个中文被拆分成2个了。
else
response.write trim(rs("newsname"))
end if
%>

最简单的方法就是用HTML中的表格控制