Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I got struggled,In below i have mentioned detaily
C#
void _SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {

      sbSPBuffer.Append(_SerialPort.ReadExisting().ToString());
      if (sbSPBuffer.ToString().IndexOf(Global.LHScannerPrefix.Trim()) != -1)
      {
        //Operation
      }
  }


C#
Global.LHScannerPrefix="\r\n";

GLobal.LHScannerPrefix is configured as enter key,It will vary depends upon scanner, sometimes it may be tab key(\t);

I have configured my serial Port scanner with suffix as enter key, So whenever i scan any barcode ,it will comes scanned data along with enter key(\r\n);
After that I will Remove the enter key ,then i do my opeations.

When i try to find the Index (GLobal.LHScannerPrefix) from scanned barcode ,its not find the mentioned value fom string. When i check the value in GLobal.LHScannerPrefix it is having "\\r\\n"

How can i achieve it.
Posted
Updated 22-Dec-15 22:37pm
v2

1 solution

You can use the IndexOf method of String class:
C#
string test = "This is a test string.\r\n";
int index = test.IndexOf("\r\n"); // index = 22
 
Share this answer
 
Comments
King Fisher 23-Dec-15 4:56am    
Sorry, Please assign the "\r\n" in any variable ,then pass the variable.
phil.o 23-Dec-15 4:59am    
I don't understand. Please clarify. And show some actual code.
King Fisher 23-Dec-15 5:08am    
string str="\r\n";
string test = "This is a test string.\r\n";
int index = test.IndexOf(str);

test now
phil.o 23-Dec-15 5:13am    
I get index = 22.
Proof
King Fisher 23-Dec-15 5:29am    
I agree,bu I have configured in COnfiguration File. so Im getting this "\\r\\n" instead of "\r\n".

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