有没有办法比较声明为的字符串与从串口接收的数据,例如:
string hello = "hello";
string dataReceived = serialPort1.ReadExisting(); //the incoming data is "hello"
bool comparisonResult = hello.Equals(dataReceived, StringComparison.Ordinal);
if(comparisonResult == true)
{
//do something
}
提前致谢!
答案 0 :(得分:0)
是的,有办法
if (serialPort1.ReadExisting() == "hello")
{
// do something
}
答案 1 :(得分:0)
编辑:找出它为什么不起作用,我需要的是文化敏感的比较
string hello = "hello";
string dataReceived = serialPort1.ReadExisting(); //incoming data is "hello"
int comparisonResult = String.Compare(hello, dataReceived, true);
//if comparisonResult is true, output is 0
if (comparisonResult == 0)
{
//do something
}