程序需要,做了一个自定义的检测函数,主要检测字符串的类型,因为需求,将和%也一同放入英文字符类型中。原理很简单,将字符拆开单取获得asc码,在什么范围就为什么类型,当然检测有局限性。
代码如下: #############################################################
名称:strtype(str)
用途:判断字符串类型
返回0-空
返回1-数字
返回2-英文
返回3-汉字
返回4-英汉
返回5-英数
返回6-汉数
返回7-全
#############################################################
function strtype(str)
on error resume next
dim i,a,e,n,c
e=false
n=false
c=false
if isnull(str) then
strtype=0
exit function
end if
if trim(str)="" then
strtype=0
exit function
end if
for i=1 to len(str)
a=asc(mid(str,i,1))
if a>=48 and a<=57 then n=true
if (a>=65 and a<=90) or (a>=97 and a<=122) or (a>=38 and a<=39) then e=true
if a<0 then c=true
next
if n and (not e) and (not c) then
strtype=1
elseif e and (not n) and (not c) then
strtype=2
elseif c and (not e) and (not n) then
strtype=3
elseif c and e and (not n) then
strtype=4
elseif n and e and (not c) then
strtype=5
elseif c and n and (not e) then
strtype=6
elseif n and e and c then
strtype=7
else
strtype=0
end if
if err.number<>0 then err.clear
end function
