28,409
社区成员




<%
dim str
str = "中文是2个字符"
response.write show(str, 7) ' 这里显示的应该是“中文是2”
function show(s, l)
' 这里怎么写啊?
end function
%>
dim str
str = "中文是2个字符"
response.write show(str, 7) ' 这里显示的应该是“中文是2”
Function show(s, l)
Dim c, n, i, a, t
n = 0
t = ""
For i= 1 To Len(s)
c = Mid(s,i,1)
a = Asc(c)
If a>=0 And a<=255 Then
n = n + 1
Else
n = n + 2
End If
If n > l Then
show = t
Exit Function
Else
t = t & c
End If
Next
show = t
end Function
'**************************************************
'函数名:substr
'作 用:截字符串,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串
' strlen ----截取长度
'返回值:截取后的字符串
'**************************************************
Function substr(ByVal str, ByVal strlen)
If str = "" or isnull(str) Then
substr = ""
Exit Function
End If
Dim l, t, c, i, strTemp
str = Replace(Replace(Replace(Replace(str, " ", " "), """, Chr(34)), ">", ">"), "<", "<")
l = Len(str)
t = 0
strTemp = str
strlen = CLng(strlen)
For i = 1 To l
c = Abs(Asc(Mid(str, i, 1)))
If c > 255 Then
t = t + 2
Else
t = t + 1
End If
If t >= strlen Then
strTemp = Left(str, i)
Exit For
End If
Next
If strTemp <> str Then
strTemp = strTemp & "…"
End If
substr = Replace(Replace(Replace(Replace(strTemp, " ", " "), Chr(34), """), ">", ">"), "<", "<")
End Function