求字符串长度一般用LEN函数能实现返回文本串的字符数
Len( text)
功能得到字符串的长度。
语法Len (string)
参数string:string类型变量返回值Long。函数执行成功时返回字符串的长度,发生错误时返回-1。假如任何参数的值为NULL,则Len()函数返回NULL。
以下是改良过的求字符串长度函数,汉字算两个字符,英文算一个字符。ASP(VBScript)语言
<%
'**************************************************
'函数名:strLength
'作 用:求字符串长度。汉字算两个字符,英文算一个字符。
'参 数:str ----要求长度的字符串
'返回值:字符串长度
'**************************************************
function strLength(str)
ON ERROR RESUME NEXT
dim WINNT_CHINESE
WINNT_CHINESE = (len("汉字")=2)
if WINNT_CHINESE then
dim l,t,c
dim i
l=len(str)
t=l
for i=1 to l
c=asc(mid(str,i,1))
if c<0 then c=c+65536
if c>255 then
t=t+1
end if
next
strLength=t
else
strLength=len(str)
end if
if err.number<>0 then err.clear
end function
%>