当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp 字符串截取函数

ASP
IIS访问ASP页面时报错The requested resource is in use.的解决办法
错误类型:Provider (0x80004005)未指定的错误 的一个处理方法
关于asp+access的安全问题分析
把RS.GetRows看得更清楚
asp下UTF-8页面乱码的解决方法
解决使用良精企业建站7.0未注册问题
在ASP中连接MySQL数据库的方法,最好的通过ODBC方法
flash与js通讯方法
ASP操作Excel相关技术总结
解决用Access数据库建站维护不便的问题的方法
ASP实现GB2312字符与区位码的相互转换的代码
对于ASP编码问题的深入研究与最终解决方案
ASP生成UTF-8编码的代码
删除A表中在B表中不存在的数据
动网防恶意广告比较有效的办法附asp代码
asp磁盘缓存技术使用的代码
网页语言编码及asp乱码问题解决方案
FSO遍历目录实现全站插马的代码
关于无限分级(ASP+数据库+JS)的实现代码
如何写ASP入库小偷程序

ASP 中的 asp 字符串截取函数


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

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