最新下载
热门教程
- 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
相关文章
- 自在江湖2025公测礼包兑换码分享 07-03
- 新三国志曹操传2025礼包兑换码汇总 07-03
- 艾媒链(IMCC币)浏览器是什么 艾媒链浏览器好用吗 07-03
- 区块链:2025年加密货币是牛市还是熊市:接下来会发生什么? 07-03
- 月圆之夜CCG白龙OTK卡组搭配推荐 07-03
- 教你使用PS将普通图片制成手绘粉笔效果 07-03