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
投稿
猜你喜欢
Go语言模拟while语句实现无限循环的方法
2024-05-09 09:45:48
python判断windows系统是32位还是64位的方法
2023-08-08 15:17:04
文本框textarea限制输入文字个数的方法
2008-01-28 13:02:00
MySQL5.6.40在CentOS7 64下安装过程详解
2024-01-12 21:56:01
Python的函数使用介绍
2022-07-02 12:05:42
详解Python用三种方式统计词频的方法
2021-02-10 13:30:12
MSSQL 2000 使用帮助(sql server简明教程)
2024-01-22 06:17:34
Sub-Pixel Bug?!
2010-03-24 18:09:00
golang逐行读取文件的操作
2023-07-10 14:39:56
JavaScript中定义函数的三种方法
2024-05-09 10:37:04
Python控制Firefox方法总结
2023-09-08 04:00:17
戴尔是如何设计新官网首页的
2008-07-08 19:02:00
JavaScript学习笔记整理_用于模式匹配的String方法
2024-06-05 09:53:02
python学习之matplotlib绘制散点图实例
2021-02-22 21:28:22
仅允许指定的机器连接SQL Server服务器
2010-07-22 19:54:00
OpenCV-Python实现人脸美白算法的实例
2023-03-27 00:33:39
一个不错的js软键盘代码而且移植方便
2007-08-14 12:56:00
python如何提取英语pdf内容并翻译
2023-06-13 13:37:27
聊聊python中not 与 is None的区别
2023-01-18 22:20:47
Python列表(list)所有元素的同一操作解析
2021-05-06 22:56:31