by Jon Mooty AKA YoungBuck (5 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Thu 1st November 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Returns the number of letters in a string, does not count numbers, spaces, or any other characters.
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
No comments have been posted about Returns the number of letters in a string, does not count numbers, spaces, or any other characters.. Why not be the first to post a comment about Returns the number of letters in a string, does not count numbers, spaces, or any other characters..