由于中文和英文字符在asp程序统计和截取时经常得到的结果不理想,这个函数可以在中英混合的字符中正确的截取指定长度的字符串
<%
'"************* 取得字符串长度 **************
Function strlen(txt)
txt=trim(txt)
x = len(txt)
y = 0
for ii = 1 to x
if trim(asc(mid(txt,ii,1)))<"0" or trim(asc(mid(txt,ii,1)))>"255" then
y = y + 2
else
y = y + 1
end if
next
strlen= y
End Function
'"************* 截取字符串 **************
Function Myleft(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
Myleft = txt
else
Myleft = ""
end if
End Function