我正在使用visual basic。我如何创建一个函数以在键入时从单词列表中读取并在编写时用可能完成的单词替换任何单词。像一个 t9 文本功能。这是我正在使用的代码。
Public Class Keyboard2
Private Property dval As Integer
Private Sub GoToNext_Click(sender As Object, e As EventArgs) Handles GoToNext.Click
'when this button is pressed the next possible word will be genereated and will replace the previous word by calling the "GetWord" Sub
GetWord()
End Sub
Private Sub GetWord()
dval = dval + 1 ' this value is used to ensure that there can be no error in word replacement and it separates each change.
Dim lastWord As String = RichTextBox1.Text.Split(" ").Last ' get the last word entered in the text box
If dval = 1 AndAlso RichTextBox1.Text.EndsWith("top") AndAlso lastWord = "top" Then
'To change the last word to the next possible word
RichTextBox1.Text = String.Concat(RichTextBox1.Text.Remove(RichTextBox1.Text.Length - lastWord.Length), "topmost")
End If
If dval = 2 AndAlso RichTextBox1.Text.EndsWith("topmost") AndAlso lastWord = "topmost" Then
RichTextBox1.Text = String.Concat(RichTextBox1.Text.Remove(RichTextBox1.Text.Length - lastWord.Length), "topping")
End If
If dval = 3 AndAlso RichTextBox1.Text.EndsWith("topping") AndAlso lastWord = "topping" Then
RichTextBox1.Text = String.Concat(RichTextBox1.Text.Remove(RichTextBox1.Text.Length - lastWord.Length), "top")
dval = 0
End If
End Sub
End Class
这种方法可能对某些人有用,我希望你会喜欢它,但对我来说这是一种非常糟糕的方法,因为我必须手动输入数千个单词。
我会用数据库做这个吗?有没有人有任何例子。谢谢你的时间。