문제

I am sending letter A (string letter = "A\n") on my android phone to a device. In matlab the code is set(s1,'Terminator', 'CR'). I would like to know how this is done from on an android phone. I want an enter after I sending letter A. Thanks for you answers in advance

도움이 되었습니까?

해결책

I have found the answer. "\n" is new line feed, "\r" is carriage return. "\n" = 10 in decimal; and "\r" = 13 in decimal. so I want 13 in decimal for Carriage return, "\r" worked for me instead of "\n". (Look at the ASCII table closer :))

다른 팁

String num = String.valueOf(number);
String cr =  String.valueOf(number_cr);
String s = num + "\n" + cr;

or you can try something like:

String eol = System.getProperty("line.separator");  
String s = num + eol + cr;

See How to insert a new line in strings in Android for more. Hope it helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top