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

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -