- Home
·
- String Manipulation
·
- Returns the number of letters in a string, does not count numbers, spaces, or any other characters.
Returns the number of letters in a string, does not count numbers, spaces, or any other characters.
Returns the number of letters in a string, does not count numbers, spaces, or any other characters.
Rate Returns the number of letters in a string, does not count numbers, spaces, or any other characters.
(1(1 Vote))
Dim iCt As Long
Dim iLetterCt As Long
Dim sChar As String * 1
For iCt = 1 To Len(s)
sChar = UCase(Mid(s, iCt, 1)) 'get current character and make it Uppercase for comparison reasons
If Asc(sChar) >= vbKeyA And Asc(sChar) <= vbKeyZ Then ' if current character is a letter
iLetterCt = iLetterCt + 1
End If
Next iCt
NumLetters = iLetterCt 'return the number of letters
End Function
'***IMPLEMENTATION***
Private Sub Form_Load()
Dim s As String
s = "HELLO WORLD"
Debug.Print NumLetters(s) 'returns 10
Debug.Print NumLetters("1234567890!@#$%^&*()") 'returns 0
Debug.Print NumLetters("This will return 22 characters!") ' self-explanatory
End Sub
Returns the number of letters in a string, does not count numbers, spaces, or any other characters. Comments
No comments yet — be the first to post one!
Post a Comment