public partial class Form1 : Form
{
const char ASC_Cr = (char)13; //Cr
const char ASC_Lf = (char)10; //Lf
…etc etc… more code here
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string ReadString;
ReadString = serialPort1.ReadLine();
ReadString = ReadString.Replace(ASC_Cr, ("¬"));
ReadString = ReadString.Replace(ASC_Lf, "¶");
Console.WriteLine("Read:" + ReadString);
}
I am trying to read the serial port and ASCII change cr and lf to the characters “¬”, and “¶” so that the debug shows exactly what I receive.
However I get the following error.
“The best overloaded method match for ‘string.Replace(char, char)’ has some invalid argument”
Argument 2: cannot convert from ‘string’ to ‘char'”
Use single-quotes, not double:
C# uses single-quotes to denote a char, and double-quotes to denote a string.