VB.NET New Line无效

时间:2015-03-11 23:36:07

标签: vb.net string newline

我的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

1 个答案:

答案 0 :(得分:1)

如果符合以下条件,请尝试添加以下内容之一:

Ch <> vbLf

或者

Ch <> ChrW(10)

我相信它在阅读RichTextBox输入时会工作。

修改

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