原创asp代码截取字符串
发布人:管理员 发布时间:2010-12-29
在进行网站建设时,我们常常会因为各种需求而要对某一字符串数量进行限制,这时asp脚本就显得非常有价值了,下面就由保定网站建设公司技术人员给大家写了一段原创的asp截取字符串的方法,仅供参考。
<%
function website(str,strlen)
if str="" then
website=""
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
website=left(str,i)
exit for
else
website=str
end if
next
website=replace(replace(replace(replace(website," "," "),chr(34),"""),">",">"),"<","<")
end function
%>
一个汉字为两个字符,一个英文字母是一个字符,str为字符串,strlen是要截取的字符数,具体用法例如:<%=website("保定网站建设公,保定网站制作,保定网络公司",20)%>
<%
function website(str,strlen)
if str="" then
website=""
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
website=left(str,i)
exit for
else
website=str
end if
next
website=replace(replace(replace(replace(website," "," "),chr(34),"""),">",">"),"<","<")
end function
%>
一个汉字为两个字符,一个英文字母是一个字符,str为字符串,strlen是要截取的字符数,具体用法例如:<%=website("保定网站建设公,保定网站制作,保定网络公司",20)%>
下一篇:网站建设需要合理的价格