Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 文本替换功能_.net_Vb.net_Visual Studio_Text - Fatal编程技术网

.net 文本替换功能

.net 文本替换功能,.net,vb.net,visual-studio,text,.net,Vb.net,Visual Studio,Text,我正在使用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 p

我正在使用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
这种方法可能对某些人有用,我希望你会喜欢,但对我来说,这是一种非常糟糕的方法,因为我必须手动输入数千个单词

我会用数据库做这个吗?有人举过例子吗。
谢谢您的时间。

我认为您最好的选择是在应用程序启动时加载到内存中的文本文件。我可以想象,您希望在运行时在文本框的当前胡萝卜位置创建一个列表框(加上一些x和y,以便文本框在列表框的上方/下方清晰可见),然后您可以在列表框中创建所有可能的选项,供用户单击正确的答案。这就是你要找的东西吗

这里有一个指向您可以使用的字典文本文件的链接,尽管只包含单词需要一些处理:


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

1) 将属性设置为
true

2) 将属性设置为
Suggest

3) 从文件中加载单词列表(您将在web上找到足够的内容),并将其设置为类似以下内容的属性:

    Dim MySource As New AutoCompleteStringCollection()
MySource.AddRange(New String() _
                    { _
                        "January", _
                        "February", _
                        "March", _
                        "April", _
                        "May", _
                        "June", _
                        "July", _
                        "August", _
                        "September", _
                        "October", _
                        "November", _
                        "December" _
                    })

textbox1.AutoCompleteCustomSource = MySource 

你还没有单词列表吗?我有一个列表,但到目前为止只添加了100个单词。我不想进一步使用此方法。它占用了大量的行数,在运行时访问该函数会停止应用程序,直到“GetWord”函数运行。@RuchmairDixon:如果您使用了IME支持,windows的语言autocomplete不是可以帮您完成吗?@RuchmairDixon:听起来像是在您的应用程序中使用中文支持语言。。。那么使用IME支持,结果如何?太慢了?它看起来不够光滑?如果你不给我更多的信息,我真的帮不了你。我已经尝试过这种方法,我制作了另一个富文本框,并将文本添加到其中,使其成为只读。然后,当我输入RichTextBox1时,它也是只读的(我通过代码将x输入RichTextBox1),然后它将RichTextBox1中的单词与RichTextBox2进行比较。但是因为它们都是只读的,所以我有一些问题,主要是当你点击只读文本框时会听到“叮”的声音。而且我不太擅长那种方法。我认为我用于该方法的代码有点原始,因为我还想用文本替换其他语言W!Top marks@Vlad L。这是内置的,太棒了,谢谢分享!看起来不错。在我开始之前,这个方法还允许我对不同的语言使用自动完成,对吗?@RuchmairDixon不确定所有的语言,但这对西里尔字母有效。试试看,很简单:)@RuchmairDixon查找相似(不相同)的单词是一项完全不同的任务,需要更复杂的算法,也许这会帮助你@VladL,这肯定会很复杂。在按下空格键输入这种语言后,我可能必须进行转换