预览模式: 普通 | 列表

Asp截取中文字符

ASP/Visual Basic代码
  1. Function GetStringLength(txt,length)  
  2. dim i  
  3. i=1  
  4. y=0  
  5. txt=trim(txt)  
  6. for i=1 to len(txt)  
  7. j=mid(txt,i,1)  
  8. if asc(j)>=0 and asc(j)<=127 then '汉字外的其他符号,如:!@#,数字,大小写英文字母  
  9. y=y+0.5  
  10. else '汉字  
  11. y=y+1  
  12. end if  
  13. if -int(-y) >= length then '截取长度  
  14. txt = left(txt,i)  
  15. exit for  
  16. end if  
  17. next  
  18. GetStringLength=txt  
  19. End Function   

Tags: asp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2885

 广告位

↑返回顶部↑