asp截取字符串方法
来源:风之相随BLOG 时间:2009-02-09 13:30:00
<%
if len(rs("title")) > 10 then '判断字符串的长度
response.Write left(rs("title"),9)&" ..."
else
response.write rs("title")
end if
%>
方法二:(函数)
a:程序代码
<%
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 '如果是汉字
'Mid(X) 读取字符串X中间的字符
' [格式]: P=Mid(X,n) 由X的第n个字符读起,读取后面的所有字符。
' P=Mid(X,n,m) 由X的第n个字符读起,读取后面的m个字符。
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
%>
b:纯粹的截取字符串
程序代码
function cutstr(thestr1,strlen)
dim l,t,c
l=len(thestr1)
if l<1 then exit function
t=0
for dxy1=1 to l
c=Abs(asc(Mid(thestr1,dxy1,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=strlen then
thev=mid(thestr1,1,dxy1)
exit for
else
thev=thestr1
end if
next
cutstr=thev
end function
c:截取字符串,不足用空格补上
程序代码
function cutstr(thestr,strlen)
dim l,t,c
l=len(thestr)
t=0
for dxy=1 to l
c=Abs(asc(Mid(thestr,dxy,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=strlen then
thev=left(thestr,dxy)
exit for
else
bu=strlen-t
for bui=1 to bu
strbu=" "
strbuall=strbuall&strbu
next
thev=thestr&strbuall
strbu=""
strbuall=""
end if
next
cutstr=thev
end function
标签:字符串,长度,函数,asp
0
投稿
猜你喜欢
oracle学习笔记(三)
2012-01-05 19:28:42
由浅到深了解JavaScript类
2008-06-16 13:20:00
网站中美好的细节
2011-07-13 18:43:07
ASP存储过程应用全接触
2007-08-18 14:28:00
css有趣而诡异的数组
2009-02-04 16:06:00
不要放弃使用CSS中的新技术
2009-05-15 12:49:00
理解HTTP消息头
2008-12-10 14:06:00
设计模式学习笔记之 - 简单工厂模式
2009-03-11 13:38:00
javascript 模拟函数指针
2009-09-19 18:02:00
MySQL 基本概念
2011-09-10 16:22:34
asp随机提取access数据库记录的几种方法
2007-09-06 19:42:00
mysql中普通索引和唯一索引的效率对比
2010-12-08 16:03:00
pjblog3相关日志功能(支持生成静态模式)
2008-11-20 13:41:00
asp连接SQL和Access数据代码(asp里的随机函数)
2013-06-01 20:26:06
SQL Server 2000中生成XML的小技巧
2009-02-13 17:12:00
asp如何处理页面执行时发生的错误?
2009-11-14 20:43:00
PHP中单引号和双引号的区别详解
2023-05-25 08:16:51
SQL提高查询效率之Like篇
2011-10-01 09:36:42
网站图片与文本谁更重要?(中英文对照)
2008-10-17 10:25:00
再读《你是一个职业的页面重构工作者吗?》
2009-02-11 12:22:00