五颜六色论坛 -> 网站建设 -> ASP控制输出字符串长度(自动区别中英文) 登录 -> 注册 -> 回复主题 -> 发表主题

无言沙漠 2006-07-09 03:29

Edit:deserts     From:5y6s.net

QUOTE:

<%
function strlen(str)
dim p_len
p_len=0
strlen=0
if trim(str)<>"" then
p_len=len(trim(str))
for xx=1 to p_len
if asc(mid(str,xx,1))<0 then
strlen=int(strlen) + 2
else
strlen=int(strlen) + 1
end if
next
end if
end function

function strvalue(str,lennum)
dim p_num
dim i
if strlen(str)<=lennum then
strvalue=str
else
p_num=0
x=0
do while not p_num > lennum-2
x=x+1
if asc(mid(str,x,1))<0 then
p_num=int(p_num) + 2
else
p_num=int(p_num) + 1
end if
strvalue=left(trim(str),x)&"…"
loop
end if
end function
%>


使用方法:

1.首先请将以上蓝框内代码转存为short.asp

2.我们使用DWMX2004新建一个ASP页面,内容如下

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%'引入公共函数模块 %>
<!--#include file="short.asp"-->

3.对目标截取输出,例如对新闻标题字段内容进行截取

<% =strvalue(rsnews.Fields.Item("title").Value,20) %> //例子1
<%=strvalue(trim(rs("title")),20)%> //例子2

无言沙漠 2006-07-09 03:44
已经按此方法测试过
可以用的

无言沙漠 2006-07-09 03:55
QUOTE:
substrs($threads[subject],20);

//$threads[subject]是本来的字符串


查看完整版本: [-- ASP控制输出字符串长度(自动区别中英文) --] [-- top --]


[ 五颜六色论坛 ]

Powered by PHPWind 5.0.1 © 2005 苏ICP备05001866号 5y6s.net
Time 0.029570 second(s),query:4 Gzip enabled