asp 字符串截取函数
网络编程 2021-07-05 10:58www.168986.cn编程入门
asp 字符串截取函数
'
'函数cutStr[str(strlen)]
'参数str,待处理的字符串,strlen,截取的长度
'作者木木
'日期2007/7/12
'描述截取指定长度的字符串
'示例<%=cutStr("欢迎光临阿里西西",5)%>
'
function cutStr(str,strlen)
If str = "" Then
cutStr = "cutStr函数异常字符串为空"
exit function
End If
'------------来源长度检查
If strlen = "" Then
cutStr = "cutStr函数异常长度未指定"
exit function
End If
If CInt(strlen) = 0 Then
cutStr = "cutStr函数异常长度为0"
exit function
End If
'----------检测来源字符长度
dim l,t,c,i
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
cutStr=left(str,i)&".."
exit for
else
cutStr=str
end if
next
cutStr=replace(cutStr,chr(10),"")
end function
''
'函数strlen[str]
'参数str,待处理的字符串
'作者木木
'日期2007/7/12
'描述判断字符串长度,汉字长度为2
'示例<%=strlen("欢迎光临阿里西西")%>
'
Function strlen(str)
dim p_len
p_len=0
strlen=0
if trim(str)<>"" then
p_len=len(trim(str))
for xx=1 to p_len
if asc(mid(str,xx,1))<0 then
strlen=int(strlen) + 2
else
strlen=int(strlen) + 1
end if
next
end if
End Function
截取左边的n个字符'
'函数LeftTrue(str,n)
'参数str,待处理的字符串,n,截取的长度
'作者木木
'日期2007/7/12
'描述显示左边的n个字符(自动识别汉字)函数
'示例<%=LeftTrue("欢迎光临阿里西西",6)%>
'
Function LeftTrue(str,n)
If len(str)<=n/2 Then
LeftTrue=str
Else
Dim TStr
Dim l,t,c
Dim i
l=len(str)
t=l
TStr=""
t=0
for i=1 to l
c=asc(mid(str,i,1))
If c<0 then c=c+65536
If c>255 then
t=t+2
Else
t=t+1
End If
If t>n Then exit for
TStr=TStr&(mid(str,i,1))
next
LeftTrue = TStr
End If
End Function
'
'函数cutStr[str(strlen)]
'参数str,待处理的字符串,strlen,截取的长度
'作者木木
'日期2007/7/12
'描述截取指定长度的字符串
'示例<%=cutStr("欢迎光临阿里西西",5)%>
'
function cutStr(str,strlen)
If str = "" Then
cutStr = "cutStr函数异常字符串为空"
exit function
End If
'------------来源长度检查
If strlen = "" Then
cutStr = "cutStr函数异常长度未指定"
exit function
End If
If CInt(strlen) = 0 Then
cutStr = "cutStr函数异常长度为0"
exit function
End If
'----------检测来源字符长度
dim l,t,c,i
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
cutStr=left(str,i)&".."
exit for
else
cutStr=str
end if
next
cutStr=replace(cutStr,chr(10),"")
end function
''
'函数strlen[str]
'参数str,待处理的字符串
'作者木木
'日期2007/7/12
'描述判断字符串长度,汉字长度为2
'示例<%=strlen("欢迎光临阿里西西")%>
'
Function strlen(str)
dim p_len
p_len=0
strlen=0
if trim(str)<>"" then
p_len=len(trim(str))
for xx=1 to p_len
if asc(mid(str,xx,1))<0 then
strlen=int(strlen) + 2
else
strlen=int(strlen) + 1
end if
next
end if
End Function
截取左边的n个字符'
'函数LeftTrue(str,n)
'参数str,待处理的字符串,n,截取的长度
'作者木木
'日期2007/7/12
'描述显示左边的n个字符(自动识别汉字)函数
'示例<%=LeftTrue("欢迎光临阿里西西",6)%>
'
Function LeftTrue(str,n)
If len(str)<=n/2 Then
LeftTrue=str
Else
Dim TStr
Dim l,t,c
Dim i
l=len(str)
t=l
TStr=""
t=0
for i=1 to l
c=asc(mid(str,i,1))
If c<0 then c=c+65536
If c>255 then
t=t+2
Else
t=t+1
End If
If t>n Then exit for
TStr=TStr&(mid(str,i,1))
next
LeftTrue = TStr
End If
End Function
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指