title: Parsing/formatting data from serial port - C#
body: <p>I've developed a small program that listens to a serial port. My program is receiving data. The problem is, its not displaying it in the desired format (one string). The data my program is receiving comes in two strings, for example:</p>
  
  <pre><code>ID:34242 State:NY
  </code></pre>
  
  <p>Zip:12345 StreetType:Ave</p>
  
  <p>Its being displayed by chunks and some of the data is passed on to next lines as such:</p>
  
  <pre><code> ID:34242
  State:N
  Y Zip:12
  345 Street
  Type:Ave
  </code></pre>
  
  <p>I have used the SerialDataReceive Event Handler to receive my data and it looks like this:</p>
  
  <pre><code> private static void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
      {
  
          SerialPort spL = (SerialPort) sender;
          int bufSize = 20;
          Byte[] dataBuffer = new Byte[bufSize];
          Console.WriteLine("Data Received at"+DateTime.Now);
          Console.WriteLine(spL.Read(dataBuffer, 0, bufSize));
          string s = System.Text.ASCIIEncoding.ASCII.GetString(dataBuffer);
          Console.WriteLine(s);
  
  
  
      }
  </code></pre>
  
  <p>As you can see, I retrieve the bytes into the buffer, create a byte array to hold the data and use ASCII encoding to translate the bytes into a string. I tried using ReadLine() but my data doesn't event get displayed with that function. Does anyone know of any other way to parse and format the data into one string?</p>