微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ASP截取字符串函数可判断汉字

我们在工作的过程中经常会用到截取字符串函数,ASP自带截取字符串函数有left、right等,但是自带函数对汉字判断不是很准确,下面编程之家跟大家分享一个自定义截取字符串函数

ASP截取字符串函数可判断汉字

'text 内容

'length 需要的长度

'技术支持 www.qdxw.net

Function InterceptString(text,length) '函数

 dim text_length

 dim count_length

 dim count

 dim ii

 text=trim(text) 

 text_length= len(text) '求字符串的长度

 count_length = 0 

 if text_length >= 1 then

 for count= 1 to text_length '这一个循环计算要截取的字符串

 if asc(mid(text,count,1)) < 0 or asc(mid(text,count,1)) >255 then '如果是汉字

 count_length = count_length + 2

 else

 count_length = count_length + 1

 end if

 if count_length >= length then

 text = left(trim(text),count)&"..." '字符串限长

 exit for

 end if

 next

 InterceptString = text '函数返回值

 else

 InterceptString = ""

 end if

End Function

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐