用VBScript编个函数
编写一个函数jiequ(mystr,mynum),该函数实现的功能如下:当需要截取的字符串少于mynum个字符,则输出原来字符串;当需要截取的字符串多于mynum个字符,...
编写一个函数jiequ(mystr,mynum),该函数实现的功能如下:
当需要截取的字符串少于mynum个字符,则输出原来字符串;
当需要截取的字符串多于mynum个字符,则截取前mynum个字符并在后面加“…”
Jiequ(“abceefefwererwerweeeeeeee”,10)
Abceefefwe… 展开
当需要截取的字符串少于mynum个字符,则输出原来字符串;
当需要截取的字符串多于mynum个字符,则截取前mynum个字符并在后面加“…”
Jiequ(“abceefefwererwerweeeeeeee”,10)
Abceefefwe… 展开
1个回答
展开全部
用这段把,动易公司开发的系统都是用搞的这个,只不是函数名称不同,但是觉得功能一样!
'**************************************************
'函数名:gotTopic
'作 用:截字符串,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串
' strlen ----截取长度
'返回值:截取后的字符串
'**************************************************
function gotTopic(str,strlen)
if str="" then
gotTopic=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
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," "," "),chr(34),"""),">",">"),"<","<")
end function
'**************************************************
'函数名:gotTopic
'作 用:截字符串,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串
' strlen ----截取长度
'返回值:截取后的字符串
'**************************************************
function gotTopic(str,strlen)
if str="" then
gotTopic=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
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," "," "),chr(34),"""),">",">"),"<","<")
end function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询