最新下载
热门教程
- 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
相关文章
- 无主之地4卡卡地亚焚毁区传奇装备掉落一览 卡卡地亚焚毁区传奇装备位置及触发条件 09-18
- 伊瑟月塔30层莎朗打法教学 09-18
- 原神5星命座免费获取方法 09-18
- 零度曙光弓箭流派搭配推荐 09-18
- 王者荣耀亚瑟荣光之誓获取攻略 09-18
- 无限暖暖音乐季隐藏任务闪闪的愿望攻略一览 09-18