gpt4 book ai didi

.net - 文本替换功能

转载 作者:行者123 更新时间:2023-12-04 04:55:47 28 4
gpt4 key购买 nike

我正在使用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

这种方法可能对某些人有用,我希望你会喜欢它,但对我来说这是一种非常糟糕的方法,因为我必须手动输入数千个单词。

我会用数据库来做这个吗?有没有人有任何例子。
谢谢你的时间。

最佳答案

在 .NET 中为您实现了所需的功能。只需执行以下操作:

1) 设置 TextBox.AutoCompleteSource属性(property)至true
2)设置TextBox.AutoCompleteMode属性(property)到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

关于.net - 文本替换功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16763998/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com