当前位置: 首页 > 图文教程 > 网络编程 > ASP > 截取实际长度字符串,并用空格替换

ASP
随机提取Access/SqlServer数据库中的10条记录的SQL语句
实现对Access数据库表重命名的一段代码
XML+XSL+CSS+ASP打造留言簿
小偷&小偷入库&采集入库
使用asp代码突破163相册的防盗连
CJJ专用ASP类库中的某个class
能不能在flash动画中给asp传递变量?
禁止站外提交表单
改进一下asp自带的formatNumber函数
收集asp的常用函数
CHR(10)表示换行,CHR(13)表示回车,CHR(32)表示空格
ASP 指南
pjblog2的参数
ASP智能搜索的实现
网站生成静态页面攻略2:数据采集
网站生成静态页面攻略3:防采集策略
网站生成静态页面攻略4:防采集而不防搜索引擎策略
简单分页函数一 常用
asp最常用的分页函数
asp:生成静态页面函数

ASP 中的 截取实际长度字符串,并用空格替换


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 63 ::
收藏到网摘: n/a

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

<%
'============================
'函数名w_cut(type,num)
'作用:字符串截取
'参数type,num
'type:字符串内容
'num:字符串被截取的长度
'=============================

Function w_cut(types,num)
dim ctypes,cnum,ci,tt,tc,cc
ctypes=types:cnum=int(num):w_cut="":tc=0:cc=0
for ci=1 to len(ctypes)
if cnum<0 then w_cut=w_cut&"...":exit for
tt=mid(ctypes,ci,1)
if int(asc(tt))>=0 then
w_cut=w_cut&tt
tc=tc+1:cc=cc+1
if tc=2 then
tc=0:cnum=cnum-1
end if
if cc>5 then cnum=cnum-1:cc=0
else
cnum=cnum-1
if cnum<=0 then w_cut=w_cut&"...":exit for
w_cut=w_cut&tt
end if
next
End Function

%>