Given a word, I need a function that returns the structure of the word in terms of vowels and consonants. "c" stands for consonants and "v" for vowels. If the letter "y" is the first letter of a word, it is a consonant, otherwise, it considered a vowel. For example, wordClass("dance") returns "cvccv" and wordClass("yucky") returns "cvccv".
I tried this but there is probably a more efficient way to do this:
Function wordClass(word As String) As String
Dim vowels(1 To 6) As String, vowelsNoY(1 To 5) As String, consonants(1 To 22) As String, pattern(1 To 5) As String
Dim i As Integer, j As Integer
vowels(1) = "a"
vowels(2) = "e"
vowels(3) = "i"
vowels(4) = "o"
vowels(5) = "u"
vowels(6) = "y"
vowelsNoY(1) = "a"
vowelsNoY(2) = "e"
vowelsNoY(3) = "i"
vowelsNoY(4) = "o"
vowelsNoY(5) = "u"
consonants(1) = "b"
consonants(2) = "c"
consonants(3) = "d"
consonants(4) = "f"
consonants(5) = "g"
consonants(6) = "h"
consonants(7) = "j"
consonants(8) = "k"
consonants(9) = "l"
consonants(10) = "m"
consonants(11) = "n"
consonants(12) = "p"
consonants(13) = "q"
consonants(14) = "r"
consonants(15) = "s"
consonants(16) = "t"
consonants(18) = "v"
consonants(19) = "w"
consonants(20) = "x"
consonants(21) = "y"
consonants(22) = "Z"
For h = 1 To Len(consonants)
If StrComp(Mid(word, 1, 1), vowelsNoY(h), vbTextCompare) = 0 Then
pattern(1) = "v"
ElseIf StrComp(Mid(word, 1, 1), consonants(h), vbTextCompare) = 0 Then
pattern(1) = "c"
End If
Next h
For i = 2 To Len(word)
For j = 2 To Len(word)
If StrComp(Mid(word, i, 1), vowels(j), vbTextCompare) = 0 Then
pattern(j) = "v"
ElseIf StrComp(Mid(word, i, 1), consonants(j), vbTextCompare) = 0 Then
pattern(j) = "c"
End If
Next j
Next i
wordClass = CStr(pattern)
End Function