VB.NET 新行不起作用



我的Else中的代码永远不会执行,尽管我的Log中有新行(richtextbox)。我试过vbNewLineEnvironment.NewLinevbCrLf..

我做错了什么?

 While (Pos < Log.Text.Length)
   Ch = Log.Text(Pos)
   If Ch <> vbNewLine AndAlso Ch <> Environment.NewLine AndAlso Ch <> vbCrLf Then
        Temp += Ch
   Else
        Messages(i) = Temp
        MsgBox(Messages(i))
        Temp = ""
        i += 1
    End If
    Pos += 1
End While

如果出现以下情况,请尝试将其中之一添加到您:

Ch <> vbLf

Ch <> ChrW(10)

我相信它会在阅读富文本框输入时起作用。

编辑

Private Sub ButtonClick_Click(sender As Object, e As EventArgs) Handles ButtonClick.Click
    Dim Log As RichTextBox = New RichTextBox()
    Log.Text = "<iframe class=""goog-te-menu-frame skiptranslate"" src=""javascript:void(0)"" frameborder=""0"" style=""display: none; visibility: visible;""></iframe><div class=""chatbox3""><div class=""chatbox2""><div class=""chatbox""><div class=""logwrapper"" style=""top: 89px; margin-right: 168px;""><div class=""logbox""><div style=""position: relative; min-height: 100%;""><div class=""logitem""><p class=""statuslog"">You're now chatting with a random stranger. Say hi!</p></div><div class=""logitem""><p class=""strangermsg""><strong class=""msgsource"">Stranger:</strong> <span>hii there</span></p></div><div class=""logitem""><p class=""strangermsg""><strong class=""msgsource"">Stranger:</strong> <span>nice to meet you</span></p></div><div class=""logitem""><p class=""strangermsg""><strong class=""msgsource"">Stranger:</strong> <span>this is a text</span></p></div><div class=""logitem""><p class=""youmsg""><strong class=""msgsource"">You:</strong> <span>this text should not be taken</span></p></div><div class=""logitem""><p class=""statuslog"">Stranger has disconnected.</p></div><div class=""logitem""><div class=""statuslog"">" & ChrW(10)
    Dim Pos As Integer = 0
    Dim Ch As Char
    While (Pos < Log.Text.Length)
        Ch = Log.Text(Pos)
        If Ch <> vbNewLine AndAlso Ch <> Environment.NewLine AndAlso Ch <> vbCrLf AndAlso Ch <> vbLf Then
            'Do nothing
        Else
            MessageBox.Show("Else")
        End If
        Pos += 1
    End While
End Sub

最新更新