注册 登录
编程论坛 ASP技术论坛

截取字符函数

chenxiang 发布于 2007-08-19 18:24, 532 次点击
if len(trim(rs("anclass")))>5 then
response.write left(trim(rs("anclass")),5)&".."
else
response.write trim(rs("anclass"))
end if
每次截取字符串的时候总象上述方法这么麻烦,请问各位大虾有没有更简单的方法,比如ASP是否有函数可以截取
3 回复
#2
multiple19022007-08-19 18:29
这还算麻烦?

你自己写个函数吧


也可以你rs在存的时候就做好Trim工作
#3
ayue2222007-08-19 22:32
function gotTopic(str,strlen)
if str="" or IsNull(str) then
gotTopic=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str,"&nbsp;"," "),"&quot;",chr(34)),"&gt;",">"),"&lt;","<")
l=len(str)
t=0
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=strlen then
gotTopic=left(str,i)
exit for
else
gotTopic=str
end if
next
gotTopic=replace(replace(replace(replace(gotTopic," ","&nbsp;"),chr(34),"&quot;"),">","&gt;"),"<","&lt;")
end function

汉字、英文都算做一个字符的函数。。。
#4
craft001wen2007-08-20 08:33
这算很简单的了
1