我有以下函数,它接受输入txtbox1
并将结果输出到txtbox2
. 要点是将每个字母替换为特定的数值,计算每个单词的值,然后显示所有单词的总和。现在,这个函数总是计算到 13。如果我输入aaa bbb cc
例如,结果应该是。我该如何修改函数来做到这一点?
aaa = 3
bbb = 15
cc = 14
Total = 32
Private Sub CountLetters(Input As String)
Dim total As Integer = 0
Dim dicLetters As New Dictionary(Of Char, Integer)
dicLetters.Add("a", 1)
dicLetters.Add("b", 5)
dicLetters.Add("c", 7)
For Each word As String In Input.Split
Dim wordtotal As Integer = 0
For Each cc As KeyValuePair(Of Char, Integer) In dicLetters
wordtotal += cc.Value
Next
total += wordtotal
'Display word totals here
txtBox2.Text += word.PadRight(12) + "=" + _
wordtotal.ToString.PadLeft(5) + vbNewLine
Next
'Display total here
txtBox2.Text += "Total".PadRight(12) + "=" + total.ToString.PadLeft(5)
End Sub