第九野,DJ野,学习,休闲,生活,分享,社区,~~~,路人乙,很高兴你能来这里! SiteMap | About Us | Guest Book | Contact Us | Search | Tags | Rss
第九野(DJ野)~生活学习休闲情感分享社区~分享一切~All for me , All for you !
Search 
<< Build A Successful Site In 12 MonthsDell技术支持年度笑话总结 >>

asp截取字符长度考虑汉字和英文字符的区别 

字体大小:   

asp截取字符长度 [考虑汉字和英文字符的区别]
<%
Function CheckStringLength(txt)
txt=trim(txt)
x = len(txt)
y = 0
for ii = 1 to x
if asc(mid(txt,ii,1))<0 or asc(mid(txt,ii,1))>255 then
y = y + 2
else
y = y + 1
end if
next
CheckStringLength = y
End Function

'"************* 截取字符串 **************
Function InterceptString(txt,length)
txt=trim(txt)
x = len(txt)
y = 0
if x >= 1 then
for ii = 1 to x
if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then
y = y + 2
else
y = y + 1
end if
if y >= length then
txt = left(trim(txt),ii) '"字符串限长
exit for
end if
next
InterceptString = txt
else
InterceptString = ""
end if
End Function
%>
<%=CheckStringLength("好好好")%>


动网截取字符函数:

'截取指定字符
Function cutStr(str,strlen)
  '去掉所有HTML标记
  Dim re
  Set re=new RegExp
  re.IgnoreCase =True
  re.Global=True
  re.Pattern="<(.[^>]*)>"
  str=re.Replace(str,"") 
  set re=Nothing
  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),"")
  cutStr=Replace(cutStr,chr(13),"")
End Function
 

<< Build A Successful Site In 12 MonthsDell技术支持年度笑话总结 >>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

网站地图 | 合作伙伴 | 隐私保护 | 版权声明 | 商业合作 | 联系我们