欢迎光临
我们一直在努力

自定义的字符串类型检测函数-ASP教程,数据库相关

建站超值云服务器,限时71元/月

程序需要,做了一个自定义的检测函数,主要检测字符串的类型,因为需求,将和%也一同放入英文字符类型中。原理很简单,将字符拆开单取获得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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 自定义的字符串类型检测函数-ASP教程,数据库相关
分享到: 更多 (0)

相关推荐

  • 暂无文章