我正在使用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这种方法可能对一些人有用,我希望你会喜欢它,但对我来说,这是一个非常糟糕的方法,因为我将不得不手动输入数千个单词。
我会用数据库做这件事吗?有没有人有什么例子。谢谢你抽出时间来。
发布于 2013-05-27 06:08:53
我们会在.NET中为您实现所需的功能。只需执行以下操作:
1)将TextBox.AutoCompleteSource属性设置为true
2)将TextBox.AutoCompleteMode属性设置为Suggest
3)从文件中加载单词列表(你可以在网上找到足够的),并将其设置为TextBox.AutoCompleteCustomSource属性,如下所示:
Dim MySource As New AutoCompleteStringCollection()
MySource.AddRange(New String() _
{ _
"January", _
"February", _
"March", _
"April", _
"May", _
"June", _
"July", _
"August", _
"September", _
"October", _
"November", _
"December" _
})
textbox1.AutoCompleteCustomSource = MySource 发布于 2013-05-27 05:53:29
我认为最好的解决方案是在应用程序启动时加载到内存中的文本文件。我想你会想要在运行时在文本框的当前胡萝卜位置创建一个列表框(加上一些x和y,这样文本框在列表框的上方/下方清晰可见),然后你可以在列表框中有所有可能的选项,让用户点击正确的答案。这就是你要找的东西吗?
下面是一个您可以使用的字典文本文件的链接,尽管它需要进行一些处理才能只包含单词:
http://www.gutenberg.org/files/29765/29765-8.txt
https://stackoverflow.com/questions/16763998
复制相似问题