我正在嘗試創建一個僅識別純字母字符并忽略特殊字符的函式。
與此類似,尋找另一個功能,即忽略特殊字符的純數字字符。
但是我的代碼沒有做我正在尋找的東西。您的幫助將不勝感激。
這是1個例子
Public Function IsLetters(s As String) As Boolean
Dim i As Long
IsLetters = False
For i = 1 To Len(s)
If Not Mid(s, i, 1) Like "[a-zA-Z]" Then Exit Function
Next i
IsLetters = True
End Function
uj5u.com熱心網友回復:
沒有數字與沒有字母
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Returns a boolean indicating whether none of the characters
' of a string are digits.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function IsNotDigits( _
ByVal SearchString As String, _
Optional ByVal IncludeNullString As Boolean = False) _
As Boolean
If Len(SearchString) > 0 Then
Dim n As Long
For n = 1 To Len(SearchString)
If Mid(SearchString, n, 1) Like "[0-9]" Then Exit Function
Next n
IsNotDigits = True
Else
If IncludeNullString Then IsNotDigits = True
End If
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Returns a boolean indicating whether none of the characters
' of a string are letters.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function IsNotLetters( _
ByVal SearchString As String, _
Optional ByVal IncludeNullString As Boolean = False) _
As Boolean
If Len(SearchString) > 0 Then
Dim n As Long
For n = 1 To Len(SearchString)
If Mid(SearchString, n, 1) Like "[A-Za-z]" Then Exit Function
Next n
IsNotLetters = True
Else
If IncludeNullString Then IsNotLetters = True
End If
End Function
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/419584.html
標籤:
