Function InterceptString(text,length) ‘函数名
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,ii,1)) < 0 or asc(mid(text,ii,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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.