求字符串長度一般用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
%>