VB.NET 换行无效
VB.NET New Line not working
我的 Else
中的代码从未执行过,尽管我的 Log
(richtextbox) 中有新行。我尝试了 vbNewLine
、Environment.NewLine
和 vbCrLf
..
我做错了什么?
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)
我相信它在读取 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
我的 Else
中的代码从未执行过,尽管我的 Log
(richtextbox) 中有新行。我尝试了 vbNewLine
、Environment.NewLine
和 vbCrLf
..
我做错了什么?
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)
我相信它在读取 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