最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
自定义的字符串类型检测函数
时间:2022-06-30 10:39:03 编辑:袖梨 来源:一聚教程网
程序需要,做了一个自定义的检测函数,主要检测字符串的类型,因为需求,将'和%也一同放入英文字符类型中。原理很简单,将字符拆开单取获得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
代码如下: '#############################################################
'名称: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
相关文章
- 鬼谷八荒逆天改命会覆盖吗 06-14
- 妄想山海植物分布图 06-14
- 栖云异梦第三章攻略 06-14
- 奥比岛手游烟花盛会活动要怎样玩 06-14
- 米坛社区官网入口-米坛社区app网页版官网登录入口v2.29.28 06-14
- iwara官网入口下载-iwara下载免费官网入口v4.87.8.4.5 06-14