gpt4 book ai didi

vb.net - 显示两个 RichTextBox 控件之间的区别

转载 作者:行者123 更新时间:2023-12-04 18:01:46 25 4
gpt4 key购买 nike

我正在尝试比较两个 richtextbox 文本并将差异显示到第三个 richtextbox 中。在我对从该论坛获得的代码进行了一些更改后,它仍然存在一些问题,即在我的第三个富文本框中显示的单词没有什么不同....富文本框的右侧是来自文本文件,在显示在框中之前已在正则表达式函数中检查过。

这是用于比较的源代码:

Dim txt1(DispBox.Text.Split(" ").Length) As String
Dim txt2(DispBox2.Text.Split(" ").Length) As String
txt1 = DispBox.Text.Split(" ")
txt2 = DispBox2.Text.Split(" ")
Dim diff1 As String = "" 'Differences between 1 and 2
Dim diff2 As String = "" 'Differences between 2 and 1
Dim diffPosition As Integer ' Set where begin to find and select in RichTextBox

diffPosition = 1 ' Initialize
For Each diff As String In txt1
If Array.IndexOf(txt2, diff.ToString) = -1 Then
diff1 += diff.ToString & " "
With DispBox
.Find(diff, diffPosition, RichTextBoxFinds.None) ' Find and select diff in RichTextBox1 starting from position diffPosition in RichtextBox1
.SelectionFont = New Font(.Font, FontStyle.Bold) ' Set diff in Bold
.SelectionColor = Color.Blue ' Set diff in blue instead of black
.SelectionBackColor = Color.Yellow ' highlight in yellow
End With
End If
diffPosition = diffPosition + Len(diff) ' re-Initialize diffPostion to avoid to find and select the same text present more than once
Next

DispBox3.Visible = True
DispBox3.Text = diff1

problems这是我用于检查正则表达式功能的上传按钮代码

Dim result As DialogResult = OpenFileDialog1.ShowDialog()

' Test result.
If result = Windows.Forms.DialogResult.OK Then

' Get the file name.
Dim path As String = OpenFileDialog1.FileName
Try
' Read in text.
Dim text As String = File.ReadAllText(path)
Dim postupload As String = Regex.Replace(text, "!", "")
DispBox2.Text = postupload

' For debugging.
Me.Text = text.Length.ToString
Catch ex As Exception
' Report an error.
Me.Text = "Error"
End Try
End If

因为文本文件里面会有“!”在线之间,我想替换“!”用“断线/输入”。

我的问题是:

  1. 为什么“Building & hostname”字词算作错误字词。
  2. 为什么第三个richtextbox显示的新词不是换行,如果在行中间找到的话。
  3. 其他错字不是颜色,加粗n高亮.....

最佳答案

您的代码根据空格拆分所有单词,但忽略了换行符,因此它使“running-confing building”看起来像一个单词。

这样试试:

Dim txt1 As String() = String.Join(" ", DispBox.Lines).Split(" ")
Dim txt2 As String() = String.Join(" ", DispBox2.Lines).Split(" ")

关于vb.net - 显示两个 RichTextBox 控件之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34226124/

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