asp函数,字符截取
一.最简单的
<%
if len(rs("title")) > 10 then '判断字符串的长度
response.Write left(rs("title"),9)&" ..."
else
response.write rs("title")
end if
%>
二.函数的。
Function InterceptString(text,length) '函数名
text=trim(text) ’忽略字符串前后的空白
text_length= len(text) '求字符串的长度
count_length = 0 ’用来计数
if text_length >= 1 then
for count= 1 to text_length '这一个循环计算要截取的字符串
if asc(mid(text,ii,1)) < 0 or asc(mid(text,ii,1)) >255 then '如果是汉字
count_length = count_length + 2
else
count_length = count_length + 1
end if
if count_length >= length then
text = left(trim(text),count) '字符串限长
exit for
end if
next
InterceptString = text '函数返回值
else
InterceptString = ""
end if
End Function
以上两个是在csdn上看到的,虽然也很实用,但感觉并不是自己想要的。所以自己动手改动了一下,将两者结合起来用,代码如下:
function cutstr(thestr,strlen)
thestr=trim(thestr) '忽略字符串前后的空白
thestr_length= len(thestr) '求字符串的长度
if thestr_length > strlen then '判断字符串的长度
response.Write left(thestr,strlen)&" ..."
else
response.write rs("title")
end if
end function
调用:<%= cutstr(rs("title"),30)%>
青岛网站建设整理发布 转载请注明。
- 百度将于12月关闭竞价排名全面切换凤巢系统 (2009-10-27 7:39:43)
- 百度收录减少 原因分析(2009-10-25 7:37:59)
- 即墨seo - 即墨网站优化 - 即墨网站建设 - 推广(2009-10-22 15:14:58)
- Meta Keywords seo中你给打多少分?(2009-10-12 9:19:52)
- 谷歌(google)收录狂飙(2009-10-10 15:46:16)
- 关键词收录与网站收录(2009-9-30 7:58:14)
- 百度空间权重占多少??(2009-9-28 7:53:9)
- 网站服务器(空间、虚拟主机)不稳定对seo的影响(2009-9-16 14:11:37)
- 百度继贴吧,图片搜索改版后 mp3也改版了(2009-8-2 16:57:48)
- 百度算法调整各栏目不断整合中。。。去知道提问(2009-7-25 16:26:24)



















◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。