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

网络编程 2021-07-05 10:57www.168986.cn编程入门

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,um,ci,tt,tc,
  ctypes=types:um=int(num):w_cut="":tc=0:=0
  for ci=1 to len(ctypes)
    if um<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:=+1
      if tc=2 then
        tc=0:um=um-1
      end if
      if >5 then um=um-1:=0
    else
      um=um-1
      if um<=0 then w_cut=w_cut&"...":exit for
      w_cut=w_cut&tt
    end if
  next
End Function

%>

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by