如何将换行符放入文本框中,该换行符仅在收到字符串“CRLF”时发生
显示 CRLF?J] 的行应该只是一个空行。
这是我正在使用的代码。
private void WriteData(string text)
{
if (text == "CRLF")
{
serial.DiscardInBuffer(); // clear "CRLF" from serial port buffer
serial.BaseStream.Flush();
OutputTextBox.AppendText("\n\n");
}
else
{
OutputTextBox.ScrollToEnd();
OutputTextBox.AppendText(text);
serial.BaseStream.Flush();
OutputTextBox.AppendText("\n");
}
}
感谢所有帮助。
试试这个。
private void WriteData(string text)
{
if (text == "CRLF")
{
serial.DiscardInBuffer(); // clear "CRLF" from serial port buffer
}
else
{
OutputTextBox.ScrollToEnd();
OutputTextBox.AppendText(text);
}
serial.BaseStream.Flush();
OutputTextBox.AppendText(Environment.NewLine);
}
private void WriteData(string text)
{
/*
I Think before you seek help,
You must specify the content of the text variable
If the content of the text variable is a raw string like
U1_1A_AA
01110101
CRLF?J]
...
Then you can replace CRLF with the help of String.replace(string oldValue, string newValue)
for example
text.replace("CRLF", "\n\n")
or
if(text.StartsWith(string value)) {
}
*/
if (text == "CRLF")
{
serial.DiscardInBuffer(); // clear "CRLF" from serial port buffer
serial.BaseStream.Flush();
OutputTextBox.AppendText("\n\n");
}
else
{
OutputTextBox.ScrollToEnd();
OutputTextBox.AppendText(text);
serial.BaseStream.Flush();
OutputTextBox.AppendText("\n");
}
}