欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP UTF-8编码下字符串截取和获取长度函数

程序员文章站 2023-02-19 13:47:49
复制代码 代码如下:'************************************ '截取文字长度函数,支持utf-8 '输入参数: ' 1、文字内容 ' 2、...
复制代码 代码如下:

'************************************
'截取文字长度函数,支持utf-8
'输入参数:
' 1、文字内容
' 2、文字最大长度
'************************************
public function cut_title(title,tlen)
dim k,i,d,c
dim istr
dim fortotal

if cdbl(tlen) > 0 then
k=0
d=strlen(title)
istr=""
fortotal = len(title)

for i=1 to fortotal
c=abs(ascw(mid(title,i,1)))
if c>255 then
k=k+2
else
k=k+1
end if

istr=istr&mid(title,i,1)

if clng(k)>clng(tlen) then
istr=istr".."
exit for
end if
next

cut_title=istr
else
cut_title=""
end if
end function

'*******************************
'检测文字长度函数,支持utf-8
'输入参数:
' 1、文字内容
'*******************************
public function strlen(strtext)
dim k,i,c
dim fortotal

k=0
fortotal = len(strtext)

for i=1 to fortotal
c=abs(ascw(mid(strtext,i,1)))
if c>255 then
k=k+2
else
k=k+1
end if
next
strlen=k

end function