java - Can't compare string received through Bluetooth with normal String -
i have connection between arduino , android phone.
this string i'm receiving: string 555, know because tested it:
final string data = new string(encodedbytes, "us-ascii"); string tocompare = data; but print false :
txtarduino.settext(string.valueof(tocompare.equals("555"))); i think format different or that, because know sure i'm receiving 555.
53 53 53 13 in ascii 5 5 5 ␍
new string converts unicode/utf-16, literal in java "555\r" or "555\u000d". so, should compare that.
final string data = new string(encodedbytes, "us-ascii"); string tocompare = data; txtarduino.settext(string.valueof(tocompare.equals("555\r"))); depending on bluetooth library, might have consider receiving stream of bytes , each read gives available bytes. split stream messages. purpose of ␍.
Comments
Post a Comment