求字符串長度一般用LEN函數(shù)能實(shí)現(xiàn)返回文本串的字符數(shù)
Len( text)
功能得到字符串的長度。
語法Len (string)
參數(shù)string:string類型變量返回值Long。函數(shù)執(zhí)行成功時(shí)返回字符串的長度,發(fā)生錯(cuò)誤時(shí)返回-1。假如任何參數(shù)的值為NULL,則Len()函數(shù)返回NULL。
以下是改良過的求字符串長度函數(shù),漢字算兩個(gè)字符,英文算一個(gè)字符。ASP(VBScript)語言
<%
'**************************************************
'函數(shù)名:strLength
'作 用:求字符串長度。漢字算兩個(gè)字符,英文算一個(gè)字符。
'參 數(shù):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
%>