字典程序编码的VB.NET问题



我正在尝试构建一个字典程序,我是这样设计的。

我使用的是一个utf8编码的txt数据库文件,它在前面的图片中。而CCD_ 1是英语和阿拉伯语单词之间的分隔符。

当我尝试翻译这样的电影字幕文件时:

1
00:00:07,376 --> 00:00:09,526
what is your name?
2
00:00:09,776 --> 00:00:12,654
jack
3
00:00:12,896 --> 00:00:15,046
nice one

问题是,每个字幕文件至少包含500行当我把它添加到字典中并按下翻译键时,不会发生任何事情它必须将整个文本识别为数据库中的一个单词,这是我正在尝试的要做的就是具有这样的功能:

http://www13.0zz0.com/2015/04/02/17/426589467.jpg

当词典翻译在其数据库中找到的单词时写了一篇没有意义的文章

最后是单选按钮1的代码,它被称为字幕我把它放在按钮1_click的代码下,它被称为翻译

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If RadioButton1.Checked = True Then
        Using reader As StreamReader = New StreamReader("Subtitles.txt")
            Do While (True)
                Dim line As String = reader.ReadLine
                If line Is Nothing Then
                    Exit Do
                End If
                Dim words As String() = line.Split("")
                Dim word As String
                For Each word In words
                    If word = TextBox1.Text Then
                        TextBox2.Text = words(+1)
                    End If
                Next
            Loop
        End Using
    End If

问题出在您的检查word = TextBox1.Text上,它检查TextBox是否只包含单词,而不包含其他单词,如果您想替换更多单词,您可以按照以下方式进行:

Using reader As StreamReader = New StreamReader("Subtitles.txt")
    Dim line As String = reader.ReadLine
    Dim translatedText As String = TextBox1.Text
    While(line IsNot Nothing)
        Dim words As String() = line.Split("")
        Dim word As String
        For Each word In words
            If translatedText.Contains(word) Then
                translatedText = translatedText.Replace(word, words(1)) 
            End If
        Next
        line = reader.ReadLine
   End While
   TextBox2.Text = translatedText
End Using

我已经改变了你的周期,因为Exit Do只是丑陋的

最新更新