Click here to Skip to main content
15,920,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
i want to receive a line without the end \n \r
but i don't want to appair in labe1l.text = the return
how to delete the return when i read a line ?
thank you

What I have tried:

static void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)

       {

        if(   TemperaturaPort.BytesToRead > 0 )
 {
               provabyte = TemperaturaPort.ReadByte();
               Ricevo =  Convert.ToString(provabyte);
               if ((provabyte == 13) || (provabyte == 10))
                       {
                   singolocarattere = Ricevo;
                   if  (singolocarattere.Contains("TempInterna:" ))
                           {
                       TemperaturaInterna = singolocarattere.Substring(13);
                       Ricevo = "";
                   }
                   if (singolocarattere.Contains("TempEsterna:"))
                   {
                       TemperaturaEsterna = singolocarattere.Substring(13);
                       Ricevo = "";
                   }
                   if (singolocarattere.Contains("TempScheda:"))
                   {
                       TemperaturaScheda = singolocarattere.Substring(13);
                       Ricevo = "";
                   }
                   if (singolocarattere.Contains("TempScheda:"))
                   {
                       TemperaturaScheda = singolocarattere.Substring(13);
                       Ricevo = "";
                   }

                   if (singolocarattere.Contains("UmiditaInterna:"))
                   {
                       TemperaturaScheda = singolocarattere.Substring(15);
                       Ricevo = "";
                   }
               }
               else
               {
                   Ricevo = Ricevo + (char)provabyte;
               }

                       {
Posted
Updated 23-Mar-17 17:37pm

If you know you are going to get both a LF and CR, then only look for one of them. Ignore the other - be sure to throw it away. Don't put it in your string.
 
Share this answer
 
serialPort1.WriteLine("Data Input String");

using WriteLine to send a string data and finish with a LF character
 
Share this answer
 
to remove the \n\r from a string use :-

...
// Read myString from Serial Port 
//
// Then Replace \r\n with Empty 
myString = myString.Replace("\r\n", string.Empty);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900