<%
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,1)) < 0 or asc(mid(text,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
%>
使用例子:
<%
Response.Write(InterceptString("abcdefffffffff",4))
%>
输出结果abcd
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,1)) < 0 or asc(mid(text,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
%>
使用例子:
<%
Response.Write(InterceptString("abcdefffffffff",4))
%>
输出结果abcd